mirror of https://github.com/apache/jclouds.git
Issue 214: leaned test a bit
This commit is contained in:
parent
53bac3fa65
commit
de359a52cc
|
@ -124,7 +124,7 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
return new MD5InputStreamResult(out.toByteArray(), eTag.digest(), length);
|
||||
}
|
||||
|
||||
private static MessageDigest getDigest() {
|
||||
public static MessageDigest getDigest() {
|
||||
MessageDigest eTag;
|
||||
try {
|
||||
eTag = MessageDigest.getInstance("MD5");
|
||||
|
|
|
@ -21,21 +21,23 @@ package org.jclouds.http.functions.config;
|
|||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.name.Named;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
@ -52,6 +54,7 @@ import com.google.inject.AbstractModule;
|
|||
import com.google.inject.ImplementedBy;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.name.Named;
|
||||
|
||||
/**
|
||||
* Contains logic for parsing objects from Strings.
|
||||
|
@ -126,17 +129,18 @@ public class ParserModule extends AbstractModule {
|
|||
return factory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Provides
|
||||
@Singleton
|
||||
Gson provideGson(DateAdapter adapter, SortedSetOfInetAddressCreator addressSetCreator,
|
||||
GsonAdapterBindings bindings) {
|
||||
GsonAdapterBindings bindings) {
|
||||
GsonBuilder gson = new GsonBuilder();
|
||||
gson.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
|
||||
gson.registerTypeAdapter(Date.class, adapter);
|
||||
gson.registerTypeAdapter(new TypeToken<SortedSet<InetAddress>>() {
|
||||
}.getType(), addressSetCreator);
|
||||
for(Map.Entry<Class, Object> binding : bindings.getBindings().entrySet()) {
|
||||
gson.registerTypeAdapter(binding.getKey(), binding.getValue());
|
||||
for (Map.Entry<Class, Object> binding : bindings.getBindings().entrySet()) {
|
||||
gson.registerTypeAdapter(binding.getKey(), binding.getValue());
|
||||
}
|
||||
return gson.create();
|
||||
}
|
||||
|
@ -195,15 +199,18 @@ public class ParserModule extends AbstractModule {
|
|||
|
||||
@Singleton
|
||||
public static class GsonAdapterBindings {
|
||||
private final Map<Class, Object> bindings = Maps.newHashMap();
|
||||
@SuppressWarnings("unchecked")
|
||||
private final Map<Class, Object> bindings = Maps.newHashMap();
|
||||
|
||||
@com.google.inject.Inject(optional=true)
|
||||
public void setBindings(@Named(Constants.PROPERTY_GSON_ADAPTERS) Map<Class, Object> bindings) {
|
||||
this.bindings.putAll(bindings);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@com.google.inject.Inject(optional = true)
|
||||
public void setBindings(@Named(Constants.PROPERTY_GSON_ADAPTERS) Map<Class, Object> bindings) {
|
||||
this.bindings.putAll(bindings);
|
||||
}
|
||||
|
||||
public Map<Class, Object> getBindings() {
|
||||
return bindings;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<Class, Object> getBindings() {
|
||||
return bindings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,21 +20,26 @@ package org.jclouds.http;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* Tests for functionality all HttpCommandExecutorServices must express. These tests will operate
|
||||
|
@ -130,33 +135,48 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests sending a big file to the server.
|
||||
* Note: this is a heavy test, takes several minutes to finish.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Test
|
||||
public void testUploadBigFile() throws IOException {
|
||||
String filename = "jclouds";
|
||||
OutputStream os = null;
|
||||
File f = null;
|
||||
try {
|
||||
//create a file, twice big as free heap memory
|
||||
f = File.createTempFile(filename, "tmp");
|
||||
f.deleteOnExit();
|
||||
long length = Runtime.getRuntime().freeMemory() * 2;
|
||||
os = new FileOutputStream(f.getAbsolutePath());
|
||||
for(long i = 0; i < length; i++) os.write('a');
|
||||
* Tests sending a big file to the server. Note: this is a heavy test, takes several minutes to
|
||||
* finish.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Test(invocationCount = 1)
|
||||
public void testUploadBigFile() throws IOException {
|
||||
String filename = "jclouds";
|
||||
OutputStream os = null;
|
||||
File f = null;
|
||||
try {
|
||||
// create a file, twice big as free heap memory
|
||||
f = File.createTempFile(filename, "tmp");
|
||||
f.deleteOnExit();
|
||||
long length = (long) (Runtime.getRuntime().freeMemory() * 1.1);
|
||||
os = new BufferedOutputStream(new FileOutputStream(f.getAbsolutePath()));
|
||||
|
||||
MessageDigest eTag = JCEEncryptionService.getDigest();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try {
|
||||
for (long i = 0; i < length; i++) {
|
||||
eTag.update((byte) 'a');
|
||||
os.write((byte) 'a');
|
||||
}
|
||||
os.flush();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
Closeables.closeQuietly(out);
|
||||
}
|
||||
|
||||
// upload and verify the response
|
||||
assertEquals(client.postWithMd5("fileso",
|
||||
this.encryptionService.toBase64String(eTag.digest()), f).trim(), "created");
|
||||
|
||||
} finally {
|
||||
if (os != null)
|
||||
os.close();
|
||||
|
||||
//upload and verify the response
|
||||
assertEquals(client.postWithMd5("fileso", f).trim(), "created");
|
||||
|
||||
} finally {
|
||||
if(os != null) os.close();
|
||||
if(f != null && f.exists()) f.delete();
|
||||
}
|
||||
}
|
||||
if (f != null && f.exists())
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
|
||||
protected AtomicInteger postFailures = new AtomicInteger();
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
package org.jclouds.http;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
@ -34,11 +32,6 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.jclouds.encryption.internal.Base64;
|
||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
@ -60,7 +53,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
|
||||
/**
|
||||
* Sample test for the behaviour of our Integration Test jetty server.
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Endpoint(Localhost.class)
|
||||
|
@ -127,6 +120,7 @@ public interface IntegrationTestAsyncClient {
|
|||
@POST
|
||||
@Path("objects/{id}")
|
||||
ListenableFuture<String> postWithMd5(@PathParam("id") String id,
|
||||
@HeaderParam("Content-MD5") String base64MD5,
|
||||
@BinderParam(BindToFilePayload.class) File file);
|
||||
|
||||
static class BindToFilePayload implements Binder {
|
||||
|
@ -134,9 +128,9 @@ public interface IntegrationTestAsyncClient {
|
|||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
File f = (File) payload;
|
||||
if (request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE) == null)
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, "application/unknown");
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_LENGTH, Collections.singletonList(f.length() + ""));
|
||||
request.getHeaders().replaceValues("Content-MD5", Collections.singletonList(Base64.encodeBytes(new JCEEncryptionService().md5(f))));
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, "application/unknown");
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_LENGTH,
|
||||
Collections.singletonList(f.length() + ""));
|
||||
request.setPayload(f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public interface IntegrationTestClient {
|
|||
|
||||
String postAsInputStream(String id, String toPut);
|
||||
|
||||
String postWithMd5(String id, File file);
|
||||
String postWithMd5(String id, String base64MD5, File file);
|
||||
|
||||
String postJson(String id, String toPut);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.gae;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -249,10 +250,16 @@ public class GaeHttpCommandExecutorServiceIntegrationTest extends
|
|||
}
|
||||
|
||||
@Override
|
||||
@Test(invocationCount = 50, timeOut = 3000)
|
||||
@Test(enabled = false)
|
||||
public void testGetBigFile() throws MalformedURLException, ExecutionException,
|
||||
InterruptedException, TimeoutException {
|
||||
// disabled since test data is too big
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test(enabled = false)
|
||||
public void testUploadBigFile() throws IOException {
|
||||
// disabled since test data is too big
|
||||
}
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
|
|||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
|
||||
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -72,4 +73,11 @@ public class NioTransformingHttpCommandExecutorServiceTest extends
|
|||
InterruptedException, TimeoutException {
|
||||
// disabled since test data is too big
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test(enabled = false)
|
||||
public void testUploadBigFile() throws IOException {
|
||||
// disabled since test data is too big
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue