mirror of https://github.com/apache/jclouds.git
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:
commit
1322a85962
|
@ -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.collect.Iterables.getLast;
|
||||||
import static com.google.common.io.ByteStreams.toByteArray;
|
import static com.google.common.io.ByteStreams.toByteArray;
|
||||||
import static com.google.common.io.Closeables.closeQuietly;
|
import static com.google.common.io.Closeables.closeQuietly;
|
||||||
|
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -60,12 +61,10 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
import org.jclouds.io.MutableContentMetadata;
|
import org.jclouds.io.MutableContentMetadata;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||||
import com.google.common.io.CountingOutputStream;
|
import com.google.common.io.CountingOutputStream;
|
||||||
|
@ -130,7 +129,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
||||||
headerBuilder.putAll(header, connection.getHeaderFields().get(header));
|
headerBuilder.putAll(header, connection.getHeaderFields().get(header));
|
||||||
}
|
}
|
||||||
ImmutableMultimap<String, String> headers = headerBuilder.build();
|
ImmutableMultimap<String, String> headers = headerBuilder.build();
|
||||||
Payload payload = in != null ? Payloads.newInputStreamPayload(in) : null;
|
Payload payload = in != null ? newInputStreamPayload(in) : null;
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
payload.getContentMetadata().setPropertiesFromHttpHeaders(headers);
|
payload.getContentMetadata().setPropertiesFromHttpHeaders(headers);
|
||||||
builder.payload(payload);
|
builder.payload(payload);
|
||||||
|
@ -202,7 +201,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
||||||
methodField.set(connection, request.getMethod());
|
methodField.set(connection, request.getMethod());
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
logger.error(e, "could not set request method: ", request.getMethod());
|
logger.error(e, "could not set request method: ", request.getMethod());
|
||||||
Throwables.propagate(e1);
|
propagate(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Optional;
|
import org.testng.annotations.Optional;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -97,6 +98,8 @@ public abstract class BaseJettyTest {
|
||||||
Handler server1Handler = new AbstractHandler() {
|
Handler server1Handler = new AbstractHandler() {
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
InputStream body = request.getInputStream();
|
||||||
|
try {
|
||||||
if (failIfNoContentLength(request, response)) {
|
if (failIfNoContentLength(request, response)) {
|
||||||
return;
|
return;
|
||||||
} else if (target.indexOf("sleep") > 0) {
|
} else if (target.indexOf("sleep") > 0) {
|
||||||
|
@ -117,7 +120,7 @@ public abstract class BaseJettyTest {
|
||||||
} else if (request.getMethod().equals("PUT")) {
|
} else if (request.getMethod().equals("PUT")) {
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.getWriter().println(Strings2.toStringAndClose(request.getInputStream()) + "PUT");
|
response.getWriter().println(Strings2.toStringAndClose(body) + "PUT");
|
||||||
} else {
|
} else {
|
||||||
response.sendError(500, "no content");
|
response.sendError(500, "no content");
|
||||||
}
|
}
|
||||||
|
@ -152,6 +155,11 @@ public abstract class BaseJettyTest {
|
||||||
response.getWriter().println(XML);
|
response.getWriter().println(XML);
|
||||||
}
|
}
|
||||||
((Request) request).setHandled(true);
|
((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 {
|
private static void handlePost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
InputStream body = request.getInputStream();
|
||||||
try {
|
try {
|
||||||
if (request.getHeader("Content-MD5") != null) {
|
if (request.getHeader("Content-MD5") != null) {
|
||||||
String expectedMd5 = request.getHeader("Content-MD5");
|
String expectedMd5 = request.getHeader("Content-MD5");
|
||||||
String realMd5FromRequest;
|
String realMd5FromRequest;
|
||||||
realMd5FromRequest = CryptoStreams.md5Base64(InputSuppliers.of(request.getInputStream()));
|
realMd5FromRequest = CryptoStreams.md5Base64(InputSuppliers.of(body));
|
||||||
boolean matched = expectedMd5.equals(realMd5FromRequest);
|
boolean matched = expectedMd5.equals(realMd5FromRequest);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
@ -185,22 +194,21 @@ public abstract class BaseJettyTest {
|
||||||
response.sendError(500, "didn't match");
|
response.sendError(500, "didn't match");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
String responseString = (request.getContentLength() < 10240) ? Strings2.toStringAndClose(body) + "POST"
|
||||||
|
: "POST";
|
||||||
|
body = null;
|
||||||
for (String header : new String[] { "Content-Disposition", HttpHeaders.CONTENT_LANGUAGE,
|
for (String header : new String[] { "Content-Disposition", HttpHeaders.CONTENT_LANGUAGE,
|
||||||
HttpHeaders.CONTENT_ENCODING })
|
HttpHeaders.CONTENT_ENCODING })
|
||||||
if (request.getHeader(header) != null) {
|
if (request.getHeader(header) != null) {
|
||||||
response.addHeader("x-" + header, request.getHeader(header));
|
response.addHeader("x-" + header, request.getHeader(header));
|
||||||
}
|
}
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
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);
|
response.getWriter().println(responseString);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} 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() {
|
Handler server2Handler = new AbstractHandler() {
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
InputStream body = request.getInputStream();
|
||||||
|
try {
|
||||||
if (request.getMethod().equals("PUT")) {
|
if (request.getMethod().equals("PUT")) {
|
||||||
|
String text = Strings2.toStringAndClose(body);
|
||||||
|
body = null;
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.getWriter().println(Strings2.toStringAndClose(request.getInputStream()) + "PUTREDIRECT");
|
response.getWriter().println(text + "PUTREDIRECT");
|
||||||
}
|
}
|
||||||
} else if (request.getMethod().equals("POST")) {
|
} else if (request.getMethod().equals("POST")) {
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
|
@ -231,6 +243,11 @@ public abstract class BaseJettyTest {
|
||||||
response.getWriter().println(XML2);
|
response.getWriter().println(XML2);
|
||||||
}
|
}
|
||||||
((Request) request).setHandled(true);
|
((Request) request).setHandled(true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (body != null)
|
||||||
|
closeQuietly(body);
|
||||||
|
response.sendError(500, Throwables.getStackTraceAsString(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,37 +61,39 @@ public class BackoffLimitedRetryHandlerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExponentialBackoffDelayDefaultMaxInterval500() throws InterruptedException {
|
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();
|
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;
|
long elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
||||||
assert (elapsedTime >= 49) : elapsedTime;
|
assert (elapsedTime >= period - 1) : elapsedTime;
|
||||||
assertTrue(elapsedTime < 50 + acceptableDelay);
|
assertTrue(elapsedTime < period + acceptableDelay);
|
||||||
|
|
||||||
startTime = System.nanoTime();
|
startTime = System.nanoTime();
|
||||||
handler.imposeBackoffExponentialDelay(2, "TEST FAILURE: 2");
|
handler.imposeBackoffExponentialDelay(period, 2, 2, 5, "TEST FAILURE: 2");
|
||||||
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
||||||
assert (elapsedTime >= 199) : elapsedTime;
|
assert (elapsedTime >= period * 4 - 1) : elapsedTime;
|
||||||
assertTrue(elapsedTime < 200 + acceptableDelay);
|
assertTrue(elapsedTime < period * 9);
|
||||||
|
|
||||||
startTime = System.nanoTime();
|
startTime = System.nanoTime();
|
||||||
handler.imposeBackoffExponentialDelay(3, "TEST FAILURE: 3");
|
handler.imposeBackoffExponentialDelay(period, 2, 3, 5, "TEST FAILURE: 3");
|
||||||
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
||||||
assert (elapsedTime >= 449) : elapsedTime;
|
assert (elapsedTime >= period * 9 - 1) : elapsedTime;
|
||||||
assertTrue(elapsedTime < 450 + acceptableDelay);
|
assertTrue(elapsedTime < period * 10);
|
||||||
|
|
||||||
startTime = System.nanoTime();
|
startTime = System.nanoTime();
|
||||||
handler.imposeBackoffExponentialDelay(4, "TEST FAILURE: 4");
|
handler.imposeBackoffExponentialDelay(period, 2, 4, 5, "TEST FAILURE: 4");
|
||||||
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
||||||
assert (elapsedTime >= 499) : elapsedTime;
|
assert (elapsedTime >= period * 10 - 1) : elapsedTime;
|
||||||
assertTrue(elapsedTime < 550 + acceptableDelay * 2);
|
assertTrue(elapsedTime < period * 11);
|
||||||
|
|
||||||
startTime = System.nanoTime();
|
startTime = System.nanoTime();
|
||||||
handler.imposeBackoffExponentialDelay(5, "TEST FAILURE: 5");
|
handler.imposeBackoffExponentialDelay(period, 2, 5, 5, "TEST FAILURE: 5");
|
||||||
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
elapsedTime = (System.nanoTime() - startTime) / 1000000;
|
||||||
assert (elapsedTime >= 499) : elapsedTime;
|
assert (elapsedTime >= period * 10 - 1) : elapsedTime;
|
||||||
assertTrue(elapsedTime < 550 + acceptableDelay * 2);
|
assertTrue(elapsedTime < period * 11);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformingHttpCommandExecutorServiceImpl executorService;
|
TransformingHttpCommandExecutorServiceImpl executorService;
|
||||||
|
|
|
@ -36,7 +36,7 @@ import com.google.common.base.Supplier;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", sequential = true)
|
@Test(groups = "unit", sequential = true)
|
||||||
public class RetryablePredicateTest {
|
public class RetryablePredicateTest {
|
||||||
public static int SLOW_BUILD_SERVER_GRACE = 50;
|
public static int SLOW_BUILD_SERVER_GRACE = 100;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFalseOnIllegalStateExeception() {
|
void testFalseOnIllegalStateExeception() {
|
||||||
|
|
|
@ -283,7 +283,14 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<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>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>integration</id>
|
<id>integration</id>
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
<targetPath>META-INF</targetPath>
|
||||||
<directory>${project.basedir}</directory>
|
<directory>${project.basedir}</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>LICENSE.txt</include>
|
<include>LICENSE.txt</include>
|
||||||
|
@ -52,10 +53,12 @@
|
||||||
<goals>
|
<goals>
|
||||||
<goal>bundle</goal>
|
<goal>bundle</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<!-- run *after* copying resources to the output directory -->
|
||||||
|
<phase>process-resources</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<resourcesDirectory>${project.basedir}</resourcesDirectory>
|
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>LICENSE.txt</include>
|
<include>META-INF/LICENSE.txt</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
|
Loading…
Reference in New Issue