You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/10/10 21:49:45 UTC
svn commit: r1630968 - in
/httpcomponents/httpasyncclient/trunk/httpasyncclient/src:
main/java/org/apache/http/impl/nio/client/
test/java/org/apache/http/localserver/
test/java/org/apache/http/nio/client/integration/
Author: olegk
Date: Fri Oct 10 19:49:45 2014
New Revision: 1630968
URL: http://svn.apache.org/r1630968
Log:
Fixed minimal async client integration tests
Added:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java
- copied, changed from r1630967, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java?rev=1630968&r1=1630967&r2=1630968&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java Fri Oct 10 19:49:45 2014
@@ -40,6 +40,7 @@ import org.apache.http.impl.DefaultConne
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
+import org.apache.http.nio.NHttpClientEventHandler;
import org.apache.http.nio.conn.NHttpClientConnectionManager;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpProcessorBuilder;
@@ -144,16 +145,18 @@ class MinimalHttpAsyncClientBuilder {
final HttpProcessor httpprocessor = b.build();
ThreadFactory threadFactory = null;
+ NHttpClientEventHandler eventHandler = null;
if (!this.connManagerShared) {
threadFactory = this.threadFactory;
if (threadFactory == null) {
threadFactory = Executors.defaultThreadFactory();
}
+ eventHandler = new LoggingAsyncRequestExecutor();
}
return new MinimalHttpAsyncClient(
connManager,
threadFactory,
- new LoggingAsyncRequestExecutor(),
+ eventHandler,
httpprocessor,
reuseStrategy,
keepAliveStrategy);
Copied: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java (from r1630967, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java?p2=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java&r1=1630967&r2=1630968&rev=1630968&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/AbstractAsyncTest.java Fri Oct 10 19:49:45 2014
@@ -36,8 +36,6 @@ import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.impl.nio.bootstrap.HttpServer;
import org.apache.http.impl.nio.bootstrap.ServerBootstrap;
-import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
-import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
@@ -48,7 +46,7 @@ import org.apache.http.nio.reactor.Liste
import org.junit.After;
import org.junit.Before;
-public abstract class HttpAsyncTestBase {
+public abstract class AbstractAsyncTest {
public enum ProtocolScheme { http, https };
@@ -56,15 +54,13 @@ public abstract class HttpAsyncTestBase
protected ServerBootstrap serverBootstrap;
protected HttpServer server;
- protected HttpAsyncClientBuilder clientBuilder;
protected PoolingNHttpClientConnectionManager connMgr;
- protected CloseableHttpAsyncClient httpclient;
- public HttpAsyncTestBase(final ProtocolScheme scheme) {
+ public AbstractAsyncTest(final ProtocolScheme scheme) {
this.scheme = scheme;
}
- public HttpAsyncTestBase() {
+ public AbstractAsyncTest() {
this(ProtocolScheme.http);
}
@@ -72,13 +68,10 @@ public abstract class HttpAsyncTestBase
return this.scheme.name();
}
- public HttpHost start() throws Exception {
+ public HttpHost startServer() throws Exception {
this.server = this.serverBootstrap.create();
this.server.start();
- this.httpclient = this.clientBuilder.build();
- this.httpclient.start();
-
final ListenerEndpoint endpoint = this.server.getEndpoint();
endpoint.waitFor();
@@ -99,7 +92,6 @@ public abstract class HttpAsyncTestBase
this.serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
}
- this.clientBuilder = HttpAsyncClientBuilder.create();
final RegistryBuilder<SchemeIOSessionStrategy> builder = RegistryBuilder.create();
builder.register("http", NoopIOSessionStrategy.INSTANCE);
if (this.scheme.equals(ProtocolScheme.https)) {
@@ -108,14 +100,10 @@ public abstract class HttpAsyncTestBase
final Registry<SchemeIOSessionStrategy> registry = builder.build();
final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
this.connMgr = new PoolingNHttpClientConnectionManager(ioReactor, registry);
- this.clientBuilder.setConnectionManager(this.connMgr);
}
@After
public void shutDown() throws Exception {
- if (this.httpclient != null) {
- this.httpclient.close();
- }
if (this.server != null) {
this.server.shutdown(10, TimeUnit.SECONDS);
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java?rev=1630968&r1=1630967&r2=1630968&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpAsyncTestBase.java Fri Oct 10 19:49:45 2014
@@ -27,98 +27,47 @@
package org.apache.http.localserver;
-import java.net.InetSocketAddress;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.http.ExceptionLogger;
import org.apache.http.HttpHost;
-import org.apache.http.config.Registry;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.impl.nio.bootstrap.HttpServer;
-import org.apache.http.impl.nio.bootstrap.ServerBootstrap;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
-import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
-import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
-import org.apache.http.impl.nio.reactor.IOReactorConfig;
-import org.apache.http.nio.conn.NoopIOSessionStrategy;
-import org.apache.http.nio.conn.SchemeIOSessionStrategy;
-import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
-import org.apache.http.nio.reactor.ListenerEndpoint;
import org.junit.After;
import org.junit.Before;
-public abstract class HttpAsyncTestBase {
-
- public enum ProtocolScheme { http, https };
-
- protected final ProtocolScheme scheme;
+public abstract class HttpAsyncTestBase extends AbstractAsyncTest{
- protected ServerBootstrap serverBootstrap;
- protected HttpServer server;
protected HttpAsyncClientBuilder clientBuilder;
- protected PoolingNHttpClientConnectionManager connMgr;
protected CloseableHttpAsyncClient httpclient;
- public HttpAsyncTestBase(final ProtocolScheme scheme) {
- this.scheme = scheme;
- }
-
public HttpAsyncTestBase() {
- this(ProtocolScheme.http);
+ super();
}
- public String getSchemeName() {
- return this.scheme.name();
+ public HttpAsyncTestBase(final ProtocolScheme scheme) {
+ super(scheme);
}
public HttpHost start() throws Exception {
- this.server = this.serverBootstrap.create();
- this.server.start();
+ final HttpHost serverEndpoint = startServer();
this.httpclient = this.clientBuilder.build();
this.httpclient.start();
- final ListenerEndpoint endpoint = this.server.getEndpoint();
- endpoint.waitFor();
-
- final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
- return new HttpHost("localhost", address.getPort(), this.scheme.name());
+ return serverEndpoint;
}
- @Before
+ @Before @Override
public void setUp() throws Exception {
- this.serverBootstrap = ServerBootstrap.bootstrap();
- final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
- .setSoTimeout(15000)
- .build();
- this.serverBootstrap.setServerInfo("TEST/1.1");
- this.serverBootstrap.setIOReactorConfig(ioReactorConfig);
- this.serverBootstrap.setExceptionLogger(ExceptionLogger.STD_ERR);
- if (this.scheme.equals(ProtocolScheme.https)) {
- this.serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
- }
-
+ super.setUp();
this.clientBuilder = HttpAsyncClientBuilder.create();
- final RegistryBuilder<SchemeIOSessionStrategy> builder = RegistryBuilder.create();
- builder.register("http", NoopIOSessionStrategy.INSTANCE);
- if (this.scheme.equals(ProtocolScheme.https)) {
- builder.register("https", new SSLIOSessionStrategy(SSLTestContexts.createClientSSLContext()));
- }
- final Registry<SchemeIOSessionStrategy> registry = builder.build();
- final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
- this.connMgr = new PoolingNHttpClientConnectionManager(ioReactor, registry);
this.clientBuilder.setConnectionManager(this.connMgr);
}
- @After
+ @After @Override
public void shutDown() throws Exception {
if (this.httpclient != null) {
this.httpclient.close();
}
- if (this.server != null) {
- this.server.shutdown(10, TimeUnit.SECONDS);
- }
+ super.shutDown();
}
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java?rev=1630968&r1=1630967&r2=1630968&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java Fri Oct 10 19:49:45 2014
@@ -33,17 +33,20 @@ import java.util.Queue;
import java.util.Random;
import java.util.concurrent.Future;
-import org.apache.http.localserver.HttpAsyncTestBase;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.apache.http.impl.nio.client.HttpAsyncClients;
+import org.apache.http.localserver.AbstractAsyncTest;
import org.apache.http.localserver.EchoHandler;
import org.apache.http.localserver.RandomHandler;
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.util.EntityUtils;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -51,7 +54,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
-public class TestHttpAsyncMinimal extends HttpAsyncTestBase {
+public class TestHttpAsyncMinimal extends AbstractAsyncTest {
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> protocols() {
@@ -61,6 +64,8 @@ public class TestHttpAsyncMinimal extend
});
}
+ protected CloseableHttpAsyncClient httpclient;
+
public TestHttpAsyncMinimal(final ProtocolScheme scheme) {
super(scheme);
}
@@ -70,6 +75,24 @@ public class TestHttpAsyncMinimal extend
super.setUp();
this.serverBootstrap.registerHandler("/echo/*", new BasicAsyncRequestHandler(new EchoHandler()));
this.serverBootstrap.registerHandler("/random/*", new BasicAsyncRequestHandler(new RandomHandler()));
+
+ this.httpclient = HttpAsyncClients.createMinimal(this.connMgr);
+ }
+
+ @After @Override
+ public void shutDown() throws Exception {
+ if (this.httpclient != null) {
+ this.httpclient.close();
+ }
+ super.shutDown();
+ }
+
+ public HttpHost start() throws Exception {
+ final HttpHost serverEndpoint = startServer();
+
+ this.httpclient.start();
+
+ return serverEndpoint;
}
@Test