diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java index 5a3873b7a..492b12887 100644 --- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java +++ b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java @@ -103,16 +103,18 @@ public class RibbonProperties { Object property = this.config.getProperty(PoolKeepAliveTime); if (property instanceof Long) { return (Long) property; + } else if (property instanceof String) { + return Long.valueOf((String) property); } return null; } - @SuppressWarnings("deprecation") public long poolKeepAliveTime() { - Object property = this.config.getProperty(PoolKeepAliveTime); - if (property instanceof Long) { - return (Long) property; + Long poolKeepAliveTime = getPoolKeepAliveTime(); + if (poolKeepAliveTime != null) { + return poolKeepAliveTime; } + return DEFAULT_POOL_KEEP_ALIVE_TIME; } diff --git a/spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonPropertiesTests.java b/spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonPropertiesTests.java new file mode 100644 index 000000000..eb414ace0 --- /dev/null +++ b/spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonPropertiesTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.springframework.cloud.netflix.ribbon; + +import com.netflix.client.config.CommonClientConfigKey; +import com.netflix.client.config.DefaultClientConfigImpl; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Spencer Gibb + */ +public class RibbonPropertiesTests { + + @Test + public void poolKeepAliveWorksWithString() { + DefaultClientConfigImpl config = new DefaultClientConfigImpl(); + config.setProperty(CommonClientConfigKey.PoolKeepAliveTime, "714"); + RibbonProperties properties = new RibbonProperties(config); + assertThat(properties.poolKeepAliveTime()).isEqualTo(714L); + assertThat(properties.getPoolKeepAliveTime()).isEqualTo(714L); + } +}