mirror of
https://github.com/spring-cloud/spring-cloud-netflix.git
synced 2026-09-17 15:49:00 +00:00
Adds ability to get keep alive time from a string.
fixes gh-3038
This commit is contained in:
+6
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+39
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user