This commit is contained in:
Spencer Gibb
2017-08-04 12:41:21 -06:00
parent 2b5860fe4f
commit c44c28dcad

View File

@@ -2,6 +2,7 @@ package org.springframework.cloud.commons.httpclient;
import java.lang.reflect.Field;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.junit.Test;
@@ -9,7 +10,6 @@ import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.assertEquals;
/**
* @author Ryan Baxter
*/
@@ -22,8 +22,7 @@ public class DefaultApacheHttpClientConnectionManagerFactoryTests {
.getDefaultMaxPerRoute());
assertEquals(2,
((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal());
Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
"pool");
Object pool = getField((connectionManager), "pool");
assertEquals(-1l, ((Long)getField(pool, "timeToLive")).longValue());
TimeUnit timeUnit = getField(pool, "tunit");
assertEquals(TimeUnit.MILLISECONDS, timeUnit);
@@ -37,13 +36,13 @@ public class DefaultApacheHttpClientConnectionManagerFactoryTests {
.getDefaultMaxPerRoute());
assertEquals(2,
((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal());
Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
"pool");
Object pool = getField((connectionManager), "pool");
assertEquals(56l, ((Long)getField(pool, "timeToLive")).longValue());
TimeUnit timeUnit = getField(pool, "tunit");
assertEquals(TimeUnit.DAYS, timeUnit);
}
@SuppressWarnings("unchecked")
protected <T> T getField(Object target, String name) {
Field field = ReflectionUtils.findField(target.getClass(), name);
ReflectionUtils.makeAccessible(field);