From 917dae7c219e28b1dbcc09b27cd6e8aeb6a93844 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sun, 28 Jun 2009 16:48:39 +0000 Subject: [PATCH] Issue 64: started logging integration tests git-svn-id: http://jclouds.googlecode.com/svn/trunk@1480 3d8758e0-26b5-11de-8745-db77d3ebf521 --- aws/core/src/test/resources/log4j.xml | 46 +++++++++++++++++++ aws/pom.xml | 12 +++++ .../org/jclouds/aws/s3/S3IntegrationTest.java | 3 +- .../internal/BaseHttpFutureCommandClient.java | 37 ++++++++------- .../JavaUrlHttpFutureCommandClient.java | 7 ++- 5 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 aws/core/src/test/resources/log4j.xml diff --git a/aws/core/src/test/resources/log4j.xml b/aws/core/src/test/resources/log4j.xml new file mode 100644 index 0000000000..dd65a0cc6c --- /dev/null +++ b/aws/core/src/test/resources/log4j.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aws/pom.xml b/aws/pom.xml index 116da38d10..79db1f6ede 100644 --- a/aws/pom.xml +++ b/aws/pom.xml @@ -58,6 +58,18 @@ test-jar test + + log4j + log4j + 1.2.14 + test + + + ${project.groupId} + jclouds-log4j + ${project.version} + test + diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java index 7f68c3256d..d2d64e35ac 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java @@ -54,6 +54,7 @@ import org.jclouds.aws.s3.internal.StubS3Connection; import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.util.S3Utils; import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.util.Utils; import org.testng.ITestContext; import org.testng.annotations.AfterGroups; @@ -218,7 +219,7 @@ public class S3IntegrationTest { protected void createLiveS3Context(String AWSAccessKeyId, String AWSSecretAccessKey) { context = buildS3ContextFactory(AWSAccessKeyId, AWSSecretAccessKey).withModule( - createHttpModule()).build(); + createHttpModule()).withModule(new Log4JLoggingModule()).build(); } public String getBucketName() throws InterruptedException, ExecutionException, TimeoutException { diff --git a/core/src/main/java/org/jclouds/http/internal/BaseHttpFutureCommandClient.java b/core/src/main/java/org/jclouds/http/internal/BaseHttpFutureCommandClient.java index 32bc863377..c14ece91fc 100644 --- a/core/src/main/java/org/jclouds/http/internal/BaseHttpFutureCommandClient.java +++ b/core/src/main/java/org/jclouds/http/internal/BaseHttpFutureCommandClient.java @@ -61,34 +61,37 @@ public abstract class BaseHttpFutureCommandClient implements HttpFutureComman public void submit(HttpFutureCommand command) { HttpRequest request = command.getRequest(); - Q nativeRequest = null; try { HttpResponse response = null; for (;;) { - logger.trace("%s - converting request %s", request.getEndPoint(), request); - for (HttpRequestFilter filter : requestFilters) { - filter.filter(request); - } - nativeRequest = convert(request); - response = invoke(nativeRequest); - int statusCode = response.getStatusCode(); - if (statusCode >= 300) { - if (retryHandler.shouldRetryRequest(command, response)) { - continue; + Q nativeRequest = null; + try { + logger.trace("%s - converting request %s", request.getEndPoint(), request); + for (HttpRequestFilter filter : requestFilters) { + filter.filter(request); + } + nativeRequest = convert(request); + response = invoke(nativeRequest); + int statusCode = response.getStatusCode(); + if (statusCode >= 300) { + if (retryHandler.shouldRetryRequest(command, response)) { + continue; + } else { + errorHandler.handleError(command, response); + break; + } + } else { - errorHandler.handleError(command, response); + processResponse(response, command); break; } - } else { - processResponse(response, command); - break; + } finally { + cleanup(nativeRequest); } } } catch (Exception e) { command.setException(new ExecutionException(String.format("error invoking request %s", request), e)); - } finally { - cleanup(nativeRequest); } } diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpFutureCommandClient.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpFutureCommandClient.java index 723a008511..cc2556c5ac 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpFutureCommandClient.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpFutureCommandClient.java @@ -57,10 +57,10 @@ public class JavaUrlHttpFutureCommandClient extends BaseHttpFutureCommandClient< @Override protected HttpResponse invoke(HttpURLConnection connection) throws IOException { - HttpResponse response = new HttpResponse(); if (logger.isTraceEnabled()) - logger.trace("%1$s - submitting request %2$s, headers: %3$s", connection.getURL() - .getHost(), connection.getURL(), connection.getRequestProperties()); + logger.trace("%1$s - submitting request %2$s", connection.getURL().getHost(), connection + .getURL()); + HttpResponse response = new HttpResponse(); InputStream in; try { in = connection.getInputStream(); @@ -132,5 +132,4 @@ public class JavaUrlHttpFutureCommandClient extends BaseHttpFutureCommandClient< if (connection != null && connection.getContentLength() == 0) connection.disconnect(); } - }