Upgraded HttpCore dependency to version 5.0-beta1

This commit is contained in:
Oleg Kalnichevski 2017-11-04 11:44:36 +01:00
parent d88e32f952
commit 389272de3a
9 changed files with 103 additions and 20 deletions

View File

@ -67,7 +67,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- TODO: does not appear to be needed; remove? -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>

View File

@ -173,6 +173,12 @@ public class AsyncRandomHandler implements AsyncServerExchangeHandler {
@Override
public void releaseResources() {
remaining = length;
}
@Override
public boolean isRepeatable() {
return true;
}
@Override

View File

@ -70,6 +70,11 @@ final class InternalAsyncEntityProducer implements AsyncEntityProducer {
return entityDetails.getContentEncoding();
}
@Override
public boolean isRepeatable() {
return false;
}
@Override
public boolean isChunked() {
return entityDetails.isChunked();

View File

@ -189,6 +189,26 @@ class LoggingIOSession implements TlsCapableIOSession {
this.session.setSocketTimeout(timeout);
}
@Override
public long getLastReadTime() {
return this.session.getLastReadTime();
}
@Override
public long getLastWriteTime() {
return this.session.getLastWriteTime();
}
@Override
public void updateReadTime() {
this.session.updateReadTime();
}
@Override
public void updateWriteTime() {
this.session.updateWriteTime();
}
@Override
public IOEventHandler getHandler() {
return this.session.getHandler();

View File

@ -27,6 +27,7 @@
package org.apache.hc.client5.http.impl.io;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -249,11 +250,7 @@ public class PoolingHttpClientConnectionManager
if (this.log.isDebugEnabled()) {
this.log.debug("Connection request: " + ConnPoolSupport.formatStats(null, route, state, this.pool));
}
//TODO: fix me.
if (log.isWarnEnabled() && Timeout.isPositive(requestTimeout)) {
log.warn("Connection request timeout is not supported");
}
final Future<PoolEntry<HttpRoute, ManagedHttpClientConnection>> leaseFuture = this.pool.lease(route, state, /** requestTimeout, */ null);
final Future<PoolEntry<HttpRoute, ManagedHttpClientConnection>> leaseFuture = this.pool.lease(route, state, requestTimeout, null);
return new LeaseRequest() {
private volatile ConnectionEndpoint endpoint;
@ -411,6 +408,11 @@ public class PoolingHttpClientConnectionManager
this.pool.closeExpired();
}
@Override
public Set<HttpRoute> getRoutes() {
return this.pool.getRoutes();
}
@Override
public int getMaxTotal() {
return this.pool.getMaxTotal();

View File

@ -29,6 +29,7 @@ package org.apache.hc.client5.http.impl.nio;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
@ -212,12 +213,8 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
log.debug("Connection request: " + ConnPoolSupport.formatStats(null, route, state, pool));
}
final ComplexFuture<AsyncConnectionEndpoint> resultFuture = new ComplexFuture<>(callback);
//TODO: fix me.
if (log.isWarnEnabled() && Timeout.isPositive(requestTimeout)) {
log.warn("Connection request timeout is not supported");
}
final Future<PoolEntry<HttpRoute, ManagedAsyncClientConnection>> leaseFuture = pool.lease(
route, state, /** requestTimeout, **/ new FutureCallback<PoolEntry<HttpRoute, ManagedAsyncClientConnection>>() {
route, state, requestTimeout, new FutureCallback<PoolEntry<HttpRoute, ManagedAsyncClientConnection>>() {
void leaseCompleted(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry) {
if (log.isDebugEnabled()) {
@ -394,6 +391,11 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
}
}
@Override
public Set<HttpRoute> getRoutes() {
return pool.getRoutes();
}
@Override
public void setMaxTotal(final int max) {
pool.setMaxTotal(max);

View File

@ -26,7 +26,9 @@
*/
package org.apache.hc.client5.http.impl.classic;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.hc.client5.http.HttpRoute;
@ -109,6 +111,11 @@ public final class MockConnPoolControl implements ConnPoolControl<HttpRoute> {
this.maxPerHostMap.putAll(map);
}
@Override
public Set<HttpRoute> getRoutes() {
return new HashSet<>(this.maxPerHostMap.keySet());
}
@Override
public String toString() {
return this.maxPerHostMap.toString();

View File

@ -43,6 +43,7 @@ import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.config.SocketConfig;
@ -50,6 +51,7 @@ import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.pool.PoolEntry;
import org.apache.hc.core5.pool.StrictConnPool;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -106,7 +108,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(conn.isOpen()).thenReturn(true);
Mockito.when(future.isCancelled()).thenReturn(false);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
final LeaseRequest connRequest1 = mgr.lease(route, null);
final ConnectionEndpoint endpoint1 = connRequest1.get(1, TimeUnit.SECONDS);
@ -133,7 +140,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(conn.isOpen()).thenReturn(true);
Mockito.when(future.isCancelled()).thenReturn(false);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
final LeaseRequest connRequest1 = mgr.lease(route, null);
final ConnectionEndpoint endpoint1 = connRequest1.get(1, TimeUnit.SECONDS);
@ -155,7 +167,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(future.isCancelled()).thenReturn(Boolean.TRUE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
final LeaseRequest connRequest1 = mgr.lease(route, null);
connRequest1.get(1, TimeUnit.SECONDS);
@ -168,7 +185,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(future.isCancelled()).thenReturn(Boolean.TRUE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenThrow(new TimeoutException());
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
final LeaseRequest connRequest1 = mgr.lease(route, null);
connRequest1.get(1, TimeUnit.SECONDS);
@ -184,7 +206,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
final LeaseRequest connRequest1 = mgr.lease(route, null);
@ -208,7 +235,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
Mockito.when(conn.isOpen()).thenReturn(Boolean.FALSE);
final LeaseRequest connRequest1 = mgr.lease(route, null);
@ -236,7 +268,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(conn.isOpen()).thenReturn(false);
Mockito.when(future.isCancelled()).thenReturn(false);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
final LeaseRequest connRequest1 = mgr.lease(route, null);
final ConnectionEndpoint endpoint1 = connRequest1.get(1, TimeUnit.SECONDS);
@ -284,7 +321,12 @@ public class TestPoolingHttpClientConnectionManager {
Mockito.when(conn.isOpen()).thenReturn(false);
Mockito.when(future.isCancelled()).thenReturn(false);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(route, null, null)).thenReturn(future);
Mockito.when(pool.lease(
Mockito.eq(route),
Mockito.eq(null),
Mockito.<Timeout>any(),
Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
.thenReturn(future);
final LeaseRequest connRequest1 = mgr.lease(route, null);
final ConnectionEndpoint endpoint1 = connRequest1.get(1, TimeUnit.SECONDS);

View File

@ -68,7 +68,7 @@
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<httpcore.version>5.0-alpha4</httpcore.version>
<httpcore.version>5.0-beta1</httpcore.version>
<log4j.version>2.9.1</log4j.version>
<commons-codec.version>1.10</commons-codec.version>
<ehcache.version>3.4.0</ehcache.version>