From 2f01afb3cc318abb27c3376962274d91fa203eb5 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Tue, 19 Apr 2011 15:23:26 -0400 Subject: [PATCH 1/4] [issue 535] Moved LICENSE.txt to META-INF in the resource bundle --- resources/pom.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/pom.xml b/resources/pom.xml index d6c08db16d..35b955d827 100644 --- a/resources/pom.xml +++ b/resources/pom.xml @@ -36,6 +36,7 @@ + META-INF ${project.basedir} LICENSE.txt @@ -46,16 +47,18 @@ maven-remote-resources-plugin 1.2 - + bundle-remote-resources bundle + + process-resources - ${project.basedir} + ${project.build.outputDirectory} - LICENSE.txt + META-INF/LICENSE.txt From d0a5278ca02d6e275d0a0e1f8f755e9c99a28680 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 20 Apr 2011 16:21:36 -0700 Subject: [PATCH 2/4] attempt to stabalize tests on build server --- .../JavaUrlHttpCommandExecutorService.java | 25 ++- .../java/org/jclouds/http/BaseJettyTest.java | 189 ++++++++++-------- .../BackoffLimitedRetryHandlerTest.java | 34 ++-- .../predicates/RetryablePredicateTest.java | 2 +- 4 files changed, 136 insertions(+), 114 deletions(-) diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index a01966fc37..176fe4072e 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -24,6 +24,8 @@ import static com.google.common.base.Throwables.propagate; import static com.google.common.collect.Iterables.getLast; import static com.google.common.io.ByteStreams.toByteArray; import static com.google.common.io.Closeables.closeQuietly; +import static org.jclouds.io.Payloads.newInputStreamPayload; +import static org.jclouds.util.Throwables2.getFirstThrowableOfType; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -60,12 +62,10 @@ import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.io.MutableContentMetadata; import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; import org.jclouds.rest.internal.RestAnnotationProcessor; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap.Builder; import com.google.common.io.CountingOutputStream; @@ -107,12 +107,15 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe InputStream in = null; try { in = consumeOnClose(connection.getInputStream()); - } catch (IOException e) { - in = bufferAndCloseStream(connection.getErrorStream()); - } catch (RuntimeException e) { - closeQuietly(in); - propagate(e); - assert false : "should have propagated exception"; + } catch (Exception e) { + IOException ioe = getFirstThrowableOfType(e, IOException.class); + if (ioe != null) { + in = bufferAndCloseStream(connection.getErrorStream()); + } else { + closeQuietly(in); + propagate(e); + assert false : "should have propagated exception"; + } } int responseCode = connection.getResponseCode(); @@ -130,7 +133,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe headerBuilder.putAll(header, connection.getHeaderFields().get(header)); } ImmutableMultimap headers = headerBuilder.build(); - Payload payload = in != null ? Payloads.newInputStreamPayload(in) : null; + Payload payload = in != null ? newInputStreamPayload(in) : null; if (payload != null) { payload.getContentMetadata().setPropertiesFromHttpHeaders(headers); builder.payload(payload); @@ -202,7 +205,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe methodField.set(connection, request.getMethod()); } catch (Exception e1) { logger.error(e, "could not set request method: ", request.getMethod()); - Throwables.propagate(e1); + propagate(e1); } } @@ -236,7 +239,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe "JDK 1.6 does not support >2GB chunks. Use chunked encoding, if possible."); connection.setFixedLengthStreamingMode(length.intValue()); if (length.intValue() > 0) { - connection.setRequestProperty("Expect", "100-continue"); + connection.setRequestProperty("Expect", "100-continue"); } } CountingOutputStream out = new CountingOutputStream(connection.getOutputStream()); diff --git a/core/src/test/java/org/jclouds/http/BaseJettyTest.java b/core/src/test/java/org/jclouds/http/BaseJettyTest.java index a830fbf88a..3822f0abf3 100644 --- a/core/src/test/java/org/jclouds/http/BaseJettyTest.java +++ b/core/src/test/java/org/jclouds/http/BaseJettyTest.java @@ -63,6 +63,7 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; @@ -86,7 +87,7 @@ public abstract class BaseJettyTest { static final Pattern actionPattern = Pattern.compile("/objects/(.*)/action/([a-z]*);?(.*)"); @BeforeTest - @Parameters({ "test-jetty-port" }) + @Parameters( { "test-jetty-port" }) public void setUpJetty(@Optional("8123") final int testPort) throws Exception { this.testPort = testPort; @@ -96,62 +97,69 @@ public abstract class BaseJettyTest { Handler server1Handler = new AbstractHandler() { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - if (failIfNoContentLength(request, response)) { - return; - } else if (target.indexOf("sleep") > 0) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - propagate(e); - } - response.setContentType("text/xml"); - response.setStatus(HttpServletResponse.SC_OK); - } else if (target.indexOf("redirect") > 0) { - response.sendRedirect("https://localhost:" + (testPort + 1) + "/"); - } else if (target.indexOf("101constitutions") > 0) { - response.setContentType("text/plain"); - response.setHeader("Content-MD5", md5); - response.setStatus(HttpServletResponse.SC_OK); - copy(oneHundredOneConstitutions.getInput(), response.getOutputStream()); - } else if (request.getMethod().equals("PUT")) { - if (request.getContentLength() > 0) { + throws IOException, ServletException { + InputStream body = request.getInputStream(); + try { + if (failIfNoContentLength(request, response)) { + return; + } else if (target.indexOf("sleep") > 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + propagate(e); + } + response.setContentType("text/xml"); + response.setStatus(HttpServletResponse.SC_OK); + } else if (target.indexOf("redirect") > 0) { + response.sendRedirect("https://localhost:" + (testPort + 1) + "/"); + } else if (target.indexOf("101constitutions") > 0) { + response.setContentType("text/plain"); + response.setHeader("Content-MD5", md5); + response.setStatus(HttpServletResponse.SC_OK); + copy(oneHundredOneConstitutions.getInput(), response.getOutputStream()); + } else if (request.getMethod().equals("PUT")) { + if (request.getContentLength() > 0) { + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println(Strings2.toStringAndClose(body) + "PUT"); + } else { + response.sendError(500, "no content"); + } + } else if (request.getMethod().equals("POST")) { + // don't redirect large objects + if (request.getContentLength() < 10240 && redirectEveryTwentyRequests(request, response)) + return; + if (failEveryTenRequests(request, response)) + return; + if (request.getContentLength() > 0) { + handlePost(request, response); + } else { + handleAction(request, response); + } + } else if (request.getHeader("range") != null) { + response.sendError(404, "no content"); + } else if (request.getHeader("test") != null) { + response.setContentType("text/plain"); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println("test"); + } else if (request.getMethod().equals("HEAD")) { + /* + * NOTE: by HTML specification, HEAD response MUST NOT include a body + */ + response.setContentType("text/xml"); response.setStatus(HttpServletResponse.SC_OK); - response.getWriter().println(Strings2.toStringAndClose(request.getInputStream()) + "PUT"); } else { - response.sendError(500, "no content"); + if (failEveryTenRequests(request, response)) + return; + response.setContentType("text/xml"); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println(XML); } - } else if (request.getMethod().equals("POST")) { - // don't redirect large objects - if (request.getContentLength() < 10240 && redirectEveryTwentyRequests(request, response)) - return; - if (failEveryTenRequests(request, response)) - return; - if (request.getContentLength() > 0) { - handlePost(request, response); - } else { - handleAction(request, response); - } - } else if (request.getHeader("range") != null) { - response.sendError(404, "no content"); - } else if (request.getHeader("test") != null) { - response.setContentType("text/plain"); - response.setStatus(HttpServletResponse.SC_OK); - response.getWriter().println("test"); - } else if (request.getMethod().equals("HEAD")) { - /* - * NOTE: by HTML specification, HEAD response MUST NOT include a body - */ - response.setContentType("text/xml"); - response.setStatus(HttpServletResponse.SC_OK); - } else { - if (failEveryTenRequests(request, response)) - return; - response.setContentType("text/xml"); - response.setStatus(HttpServletResponse.SC_OK); - response.getWriter().println(XML); + ((Request) request).setHandled(true); + } catch (IOException e) { + if (body != null) + closeQuietly(body); + response.sendError(500, Throwables.getStackTraceAsString(e)); } - ((Request) request).setHandled(true); } }; @@ -172,11 +180,12 @@ public abstract class BaseJettyTest { } private static void handlePost(HttpServletRequest request, HttpServletResponse response) throws IOException { + InputStream body = request.getInputStream(); try { if (request.getHeader("Content-MD5") != null) { String expectedMd5 = request.getHeader("Content-MD5"); String realMd5FromRequest; - realMd5FromRequest = CryptoStreams.md5Base64(InputSuppliers.of(request.getInputStream())); + realMd5FromRequest = CryptoStreams.md5Base64(InputSuppliers.of(body)); boolean matched = expectedMd5.equals(realMd5FromRequest); if (matched) { response.setStatus(HttpServletResponse.SC_OK); @@ -185,52 +194,60 @@ public abstract class BaseJettyTest { response.sendError(500, "didn't match"); } } else { + String responseString = (request.getContentLength() < 10240) ? Strings2.toStringAndClose(body) + "POST" + : "POST"; + body = null; for (String header : new String[] { "Content-Disposition", HttpHeaders.CONTENT_LANGUAGE, - HttpHeaders.CONTENT_ENCODING }) + HttpHeaders.CONTENT_ENCODING }) if (request.getHeader(header) != null) { response.addHeader("x-" + header, request.getHeader(header)); } response.setStatus(HttpServletResponse.SC_OK); - String responseString = "POST"; - if (request.getContentLength() < 10240) { - responseString = Strings2.toStringAndClose(request.getInputStream()) + "POST"; - } else { - closeQuietly(request.getInputStream()); - } response.getWriter().println(responseString); } } catch (IOException e) { - response.sendError(500, e.toString()); + if (body != null) + closeQuietly(body); + response.sendError(500, Throwables.getStackTraceAsString(e)); } } protected void setupAndStartSSLServer(final int testPort) throws Exception { Handler server2Handler = new AbstractHandler() { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - if (request.getMethod().equals("PUT")) { - if (request.getContentLength() > 0) { + throws IOException, ServletException { + InputStream body = request.getInputStream(); + try { + if (request.getMethod().equals("PUT")) { + String text = Strings2.toStringAndClose(body); + body = null; + if (request.getContentLength() > 0) { + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println(text + "PUTREDIRECT"); + } + } else if (request.getMethod().equals("POST")) { + if (request.getContentLength() > 0) { + handlePost(request, response); + } else { + handleAction(request, response); + } + } else if (request.getMethod().equals("HEAD")) { + /* + * NOTE: by HTML specification, HEAD response MUST NOT include a body + */ + response.setContentType("text/xml"); response.setStatus(HttpServletResponse.SC_OK); - response.getWriter().println(Strings2.toStringAndClose(request.getInputStream()) + "PUTREDIRECT"); - } - } else if (request.getMethod().equals("POST")) { - if (request.getContentLength() > 0) { - handlePost(request, response); } else { - handleAction(request, response); + response.setContentType("text/xml"); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println(XML2); } - } else if (request.getMethod().equals("HEAD")) { - /* - * NOTE: by HTML specification, HEAD response MUST NOT include a body - */ - response.setContentType("text/xml"); - response.setStatus(HttpServletResponse.SC_OK); - } else { - response.setContentType("text/xml"); - response.setStatus(HttpServletResponse.SC_OK); - response.getWriter().println(XML2); + ((Request) request).setHandled(true); + } catch (IOException e) { + if (body != null) + closeQuietly(body); + response.sendError(500, Throwables.getStackTraceAsString(e)); } - ((Request) request).setHandled(true); } }; @@ -261,12 +278,12 @@ public abstract class BaseJettyTest { } public static RestContextBuilder newBuilder(int testPort, - Properties properties, Module... connectionModules) { + Properties properties, Module... connectionModules) { properties.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); properties.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); RestContextSpec contextSpec = contextSpec("test", - "http://localhost:" + testPort, "1", "", "identity", null, IntegrationTestClient.class, - IntegrationTestAsyncClient.class, ImmutableSet. copyOf(connectionModules)); + "http://localhost:" + testPort, "1", "", "identity", null, IntegrationTestClient.class, + IntegrationTestAsyncClient.class, ImmutableSet. copyOf(connectionModules)); return createContextBuilder(contextSpec, properties); } @@ -300,7 +317,7 @@ public abstract class BaseJettyTest { } protected boolean redirectEveryTwentyRequests(HttpServletRequest request, HttpServletResponse response) - throws IOException { + throws IOException { if (cycle.incrementAndGet() % 20 == 0) { response.sendRedirect("http://localhost:" + (testPort + 1) + "/"); ((Request) request).setHandled(true); diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index 6a57ef6477..979ac264c5 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -61,37 +61,39 @@ public class BackoffLimitedRetryHandlerTest { @Test void testExponentialBackoffDelayDefaultMaxInterval500() throws InterruptedException { - long acceptableDelay = 25; // Delay to forgive if tests run long. + long period = 100; + long acceptableDelay = period - 1; long startTime = System.nanoTime(); - handler.imposeBackoffExponentialDelay(1, "TEST FAILURE: 1"); + handler.imposeBackoffExponentialDelay(period, 2, 1, 5, "TEST FAILURE: 1"); long elapsedTime = (System.nanoTime() - startTime) / 1000000; - assert (elapsedTime >= 49) : elapsedTime; - assertTrue(elapsedTime < 50 + acceptableDelay); + assert (elapsedTime >= period - 1) : elapsedTime; + assertTrue(elapsedTime < period + acceptableDelay); startTime = System.nanoTime(); - handler.imposeBackoffExponentialDelay(2, "TEST FAILURE: 2"); + handler.imposeBackoffExponentialDelay(period, 2, 2, 5, "TEST FAILURE: 2"); elapsedTime = (System.nanoTime() - startTime) / 1000000; - assert (elapsedTime >= 199) : elapsedTime; - assertTrue(elapsedTime < 200 + acceptableDelay); + assert (elapsedTime >= period * 4 - 1) : elapsedTime; + assertTrue(elapsedTime < period * 9); startTime = System.nanoTime(); - handler.imposeBackoffExponentialDelay(3, "TEST FAILURE: 3"); + handler.imposeBackoffExponentialDelay(period, 2, 3, 5, "TEST FAILURE: 3"); elapsedTime = (System.nanoTime() - startTime) / 1000000; - assert (elapsedTime >= 449) : elapsedTime; - assertTrue(elapsedTime < 450 + acceptableDelay); + assert (elapsedTime >= period * 9 - 1) : elapsedTime; + assertTrue(elapsedTime < period * 10); startTime = System.nanoTime(); - handler.imposeBackoffExponentialDelay(4, "TEST FAILURE: 4"); + handler.imposeBackoffExponentialDelay(period, 2, 4, 5, "TEST FAILURE: 4"); elapsedTime = (System.nanoTime() - startTime) / 1000000; - assert (elapsedTime >= 499) : elapsedTime; - assertTrue(elapsedTime < 550 + acceptableDelay * 2); + assert (elapsedTime >= period * 10 - 1) : elapsedTime; + assertTrue(elapsedTime < period * 11); startTime = System.nanoTime(); - handler.imposeBackoffExponentialDelay(5, "TEST FAILURE: 5"); + handler.imposeBackoffExponentialDelay(period, 2, 5, 5, "TEST FAILURE: 5"); elapsedTime = (System.nanoTime() - startTime) / 1000000; - assert (elapsedTime >= 499) : elapsedTime; - assertTrue(elapsedTime < 550 + acceptableDelay * 2); + assert (elapsedTime >= period * 10 - 1) : elapsedTime; + assertTrue(elapsedTime < period * 11); + } TransformingHttpCommandExecutorServiceImpl executorService; diff --git a/core/src/test/java/org/jclouds/predicates/RetryablePredicateTest.java b/core/src/test/java/org/jclouds/predicates/RetryablePredicateTest.java index 9320caa618..0ba122e6e1 100644 --- a/core/src/test/java/org/jclouds/predicates/RetryablePredicateTest.java +++ b/core/src/test/java/org/jclouds/predicates/RetryablePredicateTest.java @@ -36,7 +36,7 @@ import com.google.common.base.Supplier; */ @Test(groups = "unit", sequential = true) public class RetryablePredicateTest { - public static int SLOW_BUILD_SERVER_GRACE = 50; + public static int SLOW_BUILD_SERVER_GRACE = 100; @Test void testFalseOnIllegalStateExeception() { From cfb180f6385099447921890fe1e8f374e80aef23 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 20 Apr 2011 17:37:02 -0700 Subject: [PATCH 3/4] cleaned exception handling --- .../JavaUrlHttpCommandExecutorService.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 176fe4072e..75360ddbeb 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -25,7 +25,6 @@ import static com.google.common.collect.Iterables.getLast; import static com.google.common.io.ByteStreams.toByteArray; import static com.google.common.io.Closeables.closeQuietly; import static org.jclouds.io.Payloads.newInputStreamPayload; -import static org.jclouds.util.Throwables2.getFirstThrowableOfType; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -107,15 +106,12 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe InputStream in = null; try { in = consumeOnClose(connection.getInputStream()); - } catch (Exception e) { - IOException ioe = getFirstThrowableOfType(e, IOException.class); - if (ioe != null) { - in = bufferAndCloseStream(connection.getErrorStream()); - } else { - closeQuietly(in); - propagate(e); - assert false : "should have propagated exception"; - } + } catch (IOException e) { + in = bufferAndCloseStream(connection.getErrorStream()); + } catch (RuntimeException e) { + closeQuietly(in); + propagate(e); + assert false : "should have propagated exception"; } int responseCode = connection.getResponseCode(); From ea5495880393641f4d4b1f166f5afb2a5ee4ff0f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 20 Apr 2011 17:54:33 -0700 Subject: [PATCH 4/4] update to latest surefire --- project/pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/project/pom.xml b/project/pom.xml index 9c76a8ebaf..3892467151 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -283,7 +283,14 @@ maven-surefire-plugin - 2.8 + 2.8.1 + + + org.apache.maven.surefire + surefire-testng + 2.8.1 + + integration