Skip to content

Commit

Permalink
[RESTEASY-1025] Further tests improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
asoldano committed Jan 15, 2018
1 parent 3ab6a08 commit 19ed886
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jboss.resteasy.test.client;

import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jboss.arquillian.container.test.api.Deployment;
Expand Down Expand Up @@ -71,9 +72,8 @@ public void after() throws Exception {
@Test
public void testInputStream() throws Exception {
InputStream is = client.target(generateURL("/test")).request().get(InputStream.class);
byte[] buf = new byte[1024];
int read = is.read(buf);
String str = new String(buf, 0, read);
byte[] buf = IOUtils.toByteArray(is);
String str = new String(buf);
Assert.assertEquals("The returned inputStream doesn't contain expexted text", "hello world", str);
logger.info("Text from inputstream: " + str);
is.close();
Expand All @@ -88,10 +88,9 @@ public void testInputStream() throws Exception {
@Test
public void testInputStreamProxy() throws Exception {
InputStreamInterface proxy = client.target(generateURL("/")).proxy(InputStreamInterface.class);
byte[] buf = new byte[1024];
InputStream is = proxy.get();
int read = is.read(buf);
String str = new String(buf, 0, read);
byte[] buf = IOUtils.toByteArray(is);
String str = new String(buf);
Assert.assertEquals("The returned inputStream doesn't contain expexted text", "hello world", str);
is.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jboss.arquillian.container.test.api.Deployment;
Expand All @@ -16,6 +18,7 @@
import org.jboss.resteasy.client.jaxrs.ClientHttpEngine;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpAsyncClient4Engine;
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine;
import org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine;
import org.jboss.resteasy.test.client.other.resource.ApacheHttpClient4Resource;
Expand All @@ -41,8 +44,9 @@ public class ApacheHttpClient43Test {

protected static final Logger logger = LogManager.getLogger(ApacheHttpClient43Test.class.getName());

private Class engine1 = ApacheHttpClient43Engine.class;
private Class engine2 = URLConnectionEngine.class;
private Class<?> engine1 = ApacheHttpClient43Engine.class;
private Class<?> engine2 = URLConnectionEngine.class;
private Class<?> engine3 = ApacheHttpAsyncClient4Engine.class;

private AtomicLong counter = new AtomicLong();

Expand All @@ -61,9 +65,10 @@ public static Archive<?> deploySimpleResource() {
public void testConnectionCleanupGCBase() throws Exception {
testConnectionCleanupGC(engine1);
testConnectionCleanupGC(engine2);
testConnectionCleanupGC(engine3);
}

public void testConnectionCleanupGC(Class engine) throws Exception {
protected void testConnectionCleanupGC(Class<?> engine) throws Exception {
final Client client = createEngine(engine);
counter.set(0);

Expand Down Expand Up @@ -99,9 +104,10 @@ public void run() {
public void testConnectionCleanupAuto() throws Exception {
testConnectionCleanupAuto(engine1);
testConnectionCleanupAuto(engine2);
testConnectionCleanupAuto(engine3);
}

public void testConnectionCleanupAuto(Class engine) throws Exception {
protected void testConnectionCleanupAuto(Class<?> engine) throws Exception {
final Client client = createEngine(engine);
counter.set(0);

Expand Down Expand Up @@ -136,9 +142,10 @@ public void run() {
public void testConnectionCleanupProxy() throws Exception {
testConnectionCleanupProxy(engine1);
testConnectionCleanupProxy(engine2);
testConnectionCleanupProxy(engine3);
}

public void testConnectionCleanupProxy(Class engine) throws Exception {
protected void testConnectionCleanupProxy(Class<?> engine) throws Exception {
final ResteasyClient client = createEngine(engine);
final ApacheHttpClient4Resource proxy = client.target(PortProviderUtil.generateBaseUrl(ApacheHttpClient43Test.class.getSimpleName())).proxy(ApacheHttpClient4Resource.class);
counter.set(0);
Expand Down Expand Up @@ -177,12 +184,13 @@ public void run() {
public void testConnectionCleanupErrorGC() throws Exception {
testConnectionCleanupErrorGC(engine1);
testConnectionCleanupErrorGC(engine2);
testConnectionCleanupErrorGC(engine3);
}

/**
* This is regression test for RESTEASY-1273
*/
public void testConnectionCleanupErrorGC(Class engine) throws Exception {
protected void testConnectionCleanupErrorGC(Class<?> engine) throws Exception {
final ResteasyClient client = createEngine(engine);
final ApacheHttpClient4Resource proxy = client.target(PortProviderUtil.generateBaseUrl(ApacheHttpClient43Test.class.getSimpleName())).proxy(ApacheHttpClient4Resource.class);
counter.set(0);
Expand Down Expand Up @@ -220,12 +228,13 @@ public void run() {
public void testConnectionCleanupErrorNoGC() throws Exception {
testConnectionCleanupErrorNoGC(engine1);
testConnectionCleanupErrorNoGC(engine2);
testConnectionCleanupErrorNoGC(engine3);
}

/**
* This is regression test for RESTEASY-1273
*/
public void testConnectionCleanupErrorNoGC(Class engine) throws Exception {
protected void testConnectionCleanupErrorNoGC(Class<?> engine) throws Exception {
final ResteasyClient client = createEngine(engine);
final ApacheHttpClient4Resource proxy = client.target(PortProviderUtil.generateBaseUrl(ApacheHttpClient43Test.class.getSimpleName())).proxy(ApacheHttpClient4Resource.class);
counter.set(0);
Expand Down Expand Up @@ -268,9 +277,10 @@ public void run() {
public void testConnectionWithRequestBody() throws InterruptedException {
testConnectionWithRequestBody(engine1);
testConnectionWithRequestBody(engine2);
testConnectionWithRequestBody(engine3);
}

public void testConnectionWithRequestBody(Class engine) throws InterruptedException {
protected void testConnectionWithRequestBody(Class<?> engine) throws InterruptedException {
final ResteasyClient client = createEngine(engine);
final ApacheHttpClient4Resource proxy = client.target(PortProviderUtil.generateBaseUrl(ApacheHttpClient43Test.class.getSimpleName())).proxy(ApacheHttpClient4Resource.class);
counter.set(0);
Expand Down Expand Up @@ -309,8 +319,7 @@ private void callProxy(ApacheHttpClient4Resource proxy) {
}
}

@SuppressWarnings(value = "unchecked")
private ResteasyClient createEngine(Class engine) {
private ResteasyClient createEngine(Class<?> engine) {
RequestConfig reqConfig = RequestConfig.custom() // apache HttpClient specific
.setConnectTimeout(5000)
.setSocketTimeout(5000)
Expand All @@ -325,8 +334,14 @@ private ResteasyClient createEngine(Class engine) {

if (engine.isAssignableFrom(ApacheHttpClient43Engine.class)) {
executor = new ApacheHttpClient43Engine(httpClient);
} else {
} else if (engine.isAssignableFrom(ApacheHttpAsyncClient4Engine.class)) {
CloseableHttpAsyncClient client = HttpAsyncClientBuilder.create().setMaxConnTotal(3).build();
executor = new ApacheHttpAsyncClient4Engine(client, true);
} else if (engine.isAssignableFrom(URLConnectionEngine.class)) {
executor = new URLConnectionEngine();
} else {
Assert.fail("unknown engine");
executor = null;
}


Expand Down

0 comments on commit 19ed886

Please sign in to comment.