Merge branch 'master' of github.com:jclouds/jclouds

* 'master' of github.com:jclouds/jclouds:
  update to latest surefire
  cleaned exception handling
  attempt to stabalize tests on build server
  [issue 535] Moved LICENSE.txt to META-INF in the resource bundle
This commit is contained in:
Adrian Cole 2011-04-21 09:33:39 -07:00
commit 1322a85962
6 changed files with 140 additions and 112 deletions

View File

@ -24,6 +24,7 @@ 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 java.io.ByteArrayInputStream;
import java.io.IOException;
@ -60,12 +61,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;
@ -130,7 +129,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
headerBuilder.putAll(header, connection.getHeaderFields().get(header));
}
ImmutableMultimap<String, String> 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 +201,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);
}
}

View File

@ -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;
@ -97,6 +98,8 @@ public abstract class BaseJettyTest {
Handler server1Handler = new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
InputStream body = request.getInputStream();
try {
if (failIfNoContentLength(request, response)) {
return;
} else if (target.indexOf("sleep") > 0) {
@ -117,7 +120,7 @@ public abstract class BaseJettyTest {
} else if (request.getMethod().equals("PUT")) {
if (request.getContentLength() > 0) {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(Strings2.toStringAndClose(request.getInputStream()) + "PUT");
response.getWriter().println(Strings2.toStringAndClose(body) + "PUT");
} else {
response.sendError(500, "no content");
}
@ -152,6 +155,11 @@ public abstract class BaseJettyTest {
response.getWriter().println(XML);
}
((Request) request).setHandled(true);
} catch (IOException e) {
if (body != null)
closeQuietly(body);
response.sendError(500, Throwables.getStackTraceAsString(e));
}
}
};
@ -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,22 +194,21 @@ 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 })
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));
}
}
@ -208,10 +216,14 @@ public abstract class BaseJettyTest {
Handler server2Handler = new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
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(Strings2.toStringAndClose(request.getInputStream()) + "PUTREDIRECT");
response.getWriter().println(text + "PUTREDIRECT");
}
} else if (request.getMethod().equals("POST")) {
if (request.getContentLength() > 0) {
@ -231,6 +243,11 @@ public abstract class BaseJettyTest {
response.getWriter().println(XML2);
}
((Request) request).setHandled(true);
} catch (IOException e) {
if (body != null)
closeQuietly(body);
response.sendError(500, Throwables.getStackTraceAsString(e));
}
}
};

View File

@ -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;

View File

@ -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() {

View File

@ -283,7 +283,14 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
<version>2.8.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>integration</id>

View File

@ -36,6 +36,7 @@
<build>
<resources>
<resource>
<targetPath>META-INF</targetPath>
<directory>${project.basedir}</directory>
<includes>
<include>LICENSE.txt</include>
@ -52,10 +53,12 @@
<goals>
<goal>bundle</goal>
</goals>
<!-- run *after* copying resources to the output directory -->
<phase>process-resources</phase>
<configuration>
<resourcesDirectory>${project.basedir}</resourcesDirectory>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<includes>
<include>LICENSE.txt</include>
<include>META-INF/LICENSE.txt</include>
</includes>
</configuration>
</execution>