From 7c13c01cb6a62b86478aa53d3516ae8aaea48bca Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 11 Sep 2020 08:59:34 +0200 Subject: [PATCH] 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 --- .../cassandra/CassandraAutoConfiguration.java | 6 +++--- .../autoconfigure/cassandra/CassandraProperties.java | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index 19cb762a3c6..7e267f8f74c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -146,11 +146,11 @@ public class CassandraAutoConfiguration { } private void mapPoolingOptions(CassandraProperties properties, CassandraDriverOptions options) { - PropertyMapper map = PropertyMapper.get(); + PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); CassandraProperties.Pool poolProperties = properties.getPool(); - map.from(poolProperties::getIdleTimeout).whenNonNull().asInt(Duration::getSeconds) + map.from(poolProperties::getIdleTimeout).asInt(Duration::toMillis) .to((idleTimeout) -> options.add(DefaultDriverOption.HEARTBEAT_TIMEOUT, idleTimeout)); - map.from(poolProperties::getHeartbeatInterval).whenNonNull().asInt(Duration::getSeconds) + map.from(poolProperties::getHeartbeatInterval).asInt(Duration::toMillis) .to((heartBeatInterval) -> options.add(DefaultDriverOption.HEARTBEAT_INTERVAL, heartBeatInterval)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java index f4f2ce08595..df6a9837465 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraProperties.java @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.cassandra; import java.time.Duration; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -26,7 +25,6 @@ import com.datastax.oss.driver.api.core.DefaultConsistencyLevel; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; -import org.springframework.boot.convert.DurationUnit; /** * Configuration properties for Cassandra. @@ -360,18 +358,14 @@ public class CassandraProperties { public static class Pool { /** - * Idle timeout before an idle connection is removed. If a duration suffix is not - * specified, seconds will be used. + * Idle timeout before an idle connection is removed. */ - @DurationUnit(ChronoUnit.SECONDS) private Duration idleTimeout = Duration.ofSeconds(120); /** * Heartbeat interval after which a message is sent on an idle connection to make - * sure it's still alive. If a duration suffix is not specified, seconds will be - * used. + * sure it's still alive. */ - @DurationUnit(ChronoUnit.SECONDS) private Duration heartbeatInterval = Duration.ofSeconds(30); public Duration getIdleTimeout() {