Formatting.

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2572 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
sharedocs1@gmail.com 2010-01-02 18:56:21 +00:00
parent 71ddcd5c87
commit 51b5f2583e
1 changed files with 120 additions and 118 deletions

View File

@ -58,144 +58,146 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
* Starts up the Google App Engine for Java Development environment and deploys an application which * Starts up the Google App Engine for Java Development environment and deploys
* tests accesses twitter and blobstores. * an application which tests accesses twitter and blobstores.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", sequential = true, testName = "functionalTests") @Test(groups = "live", sequential = true, testName = "functionalTests")
public class TweetStoreLiveTest { public class TweetStoreLiveTest {
GoogleDevServer server; GoogleDevServer server;
private URL url; private URL url;
private ImmutableSet<BlobStoreContext<? extends Object, ? extends Object>> contexts; private ImmutableSet<BlobStoreContext<? extends Object, ? extends Object>> contexts;
private String container; private String container;
@BeforeTest @BeforeTest
@Parameters( { "warfile", "devappserver.address", "devappserver.port" }) @Parameters( { "warfile", "devappserver.address", "devappserver.port" })
public void startDevAppServer(final String warfile, final String address, final String port) public void startDevAppServer(final String warfile, final String address,
throws Exception { final String port) throws Exception {
url = new URL(String.format("http://%s:%s", address, port)); url = new URL(String.format("http://%s:%s", address, port));
Properties props = new Properties(); Properties props = new Properties();
props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, checkNotNull(System props.setProperty(PROPERTY_TWEETSTORE_CONTAINER,
.getProperty(PROPERTY_TWEETSTORE_CONTAINER))); checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER));
props.setProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS, props.setProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS,
// WATCH THIS.. when adding a new context, you must update the string // WATCH THIS.. when adding a new context, you must update the string
String.format("%s,%s,%s", S3BlobStoreContextBuilder.class.getName(), String.format("%s,%s,%s", S3BlobStoreContextBuilder.class.getName(),
CloudFilesBlobStoreContextBuilder.class.getName(), CloudFilesBlobStoreContextBuilder.class.getName(),
AzureBlobStoreContextBuilder.class.getName())); AzureBlobStoreContextBuilder.class.getName()));
props = new TwitterPropertiesBuilder(props).withCredentials( props = new TwitterPropertiesBuilder(props).withCredentials(
checkNotNull(System.getProperty(PROPERTY_TWITTER_USER), PROPERTY_TWITTER_USER), checkNotNull(System.getProperty(PROPERTY_TWITTER_USER), PROPERTY_TWITTER_USER),
System.getProperty(PROPERTY_TWITTER_PASSWORD, PROPERTY_TWITTER_PASSWORD)).build(); System.getProperty(PROPERTY_TWITTER_PASSWORD, PROPERTY_TWITTER_PASSWORD))
.build();
props = new S3PropertiesBuilder(props) props = new S3PropertiesBuilder(props).withCredentials(
.withCredentials( checkNotNull(System.getProperty(PROPERTY_AWS_ACCESSKEYID), PROPERTY_AWS_ACCESSKEYID),
checkNotNull(System.getProperty(PROPERTY_AWS_ACCESSKEYID), System.getProperty(PROPERTY_AWS_SECRETACCESSKEY, PROPERTY_AWS_SECRETACCESSKEY))
PROPERTY_AWS_ACCESSKEYID), .build();
System.getProperty(PROPERTY_AWS_SECRETACCESSKEY,
PROPERTY_AWS_SECRETACCESSKEY)).build();
props = new CloudFilesPropertiesBuilder(props).withCredentials( props = new CloudFilesPropertiesBuilder(props).withCredentials(
checkNotNull(System.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), checkNotNull(System.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER),
System.getProperty(PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY)).build(); System.getProperty(PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY))
.build();
props = new AzureBlobPropertiesBuilder(props).withCredentials( props = new AzureBlobPropertiesBuilder(props).withCredentials(
checkNotNull(System.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), checkNotNull(System.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT),
PROPERTY_AZURESTORAGE_ACCOUNT), System.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY))
System.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY)).build(); .build();
server = new GoogleDevServer(); server = new GoogleDevServer();
server.writePropertiesAndStartServer(address, port, warfile, props); server.writePropertiesAndStartServer(address, port, warfile, props);
} }
@BeforeClass @BeforeClass
void clearAndCreateContainers() throws InterruptedException, ExecutionException, void clearAndCreateContainers() throws InterruptedException,
TimeoutException { ExecutionException, TimeoutException {
container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER)); container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER));
BlobStoreContext<?, ?> s3Context = S3BlobStoreContextFactory.createContext(checkNotNull( BlobStoreContext<?, ?> s3Context = S3BlobStoreContextFactory.createContext(
System.getProperty(PROPERTY_AWS_ACCESSKEYID), PROPERTY_AWS_ACCESSKEYID), System checkNotNull(System.getProperty(PROPERTY_AWS_ACCESSKEYID), PROPERTY_AWS_ACCESSKEYID),
.getProperty(PROPERTY_AWS_SECRETACCESSKEY, PROPERTY_AWS_SECRETACCESSKEY)); System.getProperty(PROPERTY_AWS_SECRETACCESSKEY, PROPERTY_AWS_SECRETACCESSKEY));
BlobStoreContext<?, ?> cfContext = CloudFilesBlobStoreContextFactory.createContext( BlobStoreContext<?, ?> cfContext = CloudFilesBlobStoreContextFactory.createContext(
checkNotNull(System.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), checkNotNull(System.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER),
System.getProperty(PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY)); System.getProperty(PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY));
BlobStoreContext<?, ?> azContext = AzureBlobStoreContextFactory.createContext(checkNotNull( BlobStoreContext<?, ?> azContext = AzureBlobStoreContextFactory.createContext(
System.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT), checkNotNull(System.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), PROPERTY_AZURESTORAGE_ACCOUNT),
System.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY)); System.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY));
this.contexts = ImmutableSet.of(s3Context, cfContext, azContext); this.contexts = ImmutableSet.of(s3Context, cfContext, azContext);
boolean deleted = false; boolean deleted = false;
for (BlobStoreContext<?, ?> context : contexts) { for (BlobStoreContext<?, ?> context : contexts) {
if (context.getBlobStore().containerExists(container)) { if (context.getBlobStore().containerExists(container)) {
System.err.printf("deleting container %s at %s%n", container, context.getEndPoint()); System.err.printf("deleting container %s at %s%n", container,
context.getBlobStore().deleteContainer(container); context.getEndPoint());
deleted = true; context.getBlobStore().deleteContainer(container);
} deleted = true;
} }
if (deleted) { }
System.err.println("sleeping 30 seconds to allow containers to clear"); if (deleted) {
Thread.sleep(30000); System.err.println("sleeping 30 seconds to allow containers to clear");
} Thread.sleep(30000);
for (BlobStoreContext<?, ?> context : contexts) { }
System.err.printf("creating container %s at %s%n", container, context.getEndPoint()); for (BlobStoreContext<?, ?> context : contexts) {
context.getBlobStore().createContainer(container); System.err.printf("creating container %s at %s%n", container,
} context.getEndPoint());
if (deleted) { context.getBlobStore().createContainer(container);
System.err.println("sleeping 5 seconds to allow containers to create"); }
Thread.sleep(30000); if (deleted) {
} System.err.println("sleeping 5 seconds to allow containers to create");
} Thread.sleep(30000);
}
}
@Test @Test
public void shouldPass() throws InterruptedException, IOException { public void shouldPass() throws InterruptedException, IOException {
InputStream i = url.openStream(); InputStream i = url.openStream();
String string = Utils.toStringAndClose(i); String string = Utils.toStringAndClose(i);
assert string.indexOf("Welcome") >= 0 : string; assert string.indexOf("Welcome") >= 0 : string;
} }
@Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class)
public void shouldFail() throws InterruptedException, IOException { public void shouldFail() throws InterruptedException, IOException {
new URL(url, "/store/do").openStream(); new URL(url, "/store/do").openStream();
} }
@Test(dependsOnMethods = "shouldFail") @Test(dependsOnMethods = "shouldFail")
public void testPrimeContainers() throws IOException, InterruptedException { public void testPrimeContainers() throws IOException, InterruptedException {
URL gurl = new URL(url, "/store/do"); URL gurl = new URL(url, "/store/do");
for (String context : new String[] { "S3", "Azure", "CloudFiles" }) { for (String context : new String[] { "S3", "Azure", "CloudFiles" }) {
System.out.println("storing at context: " + context); System.out.println("storing at context: " + context);
HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); HttpURLConnection connection = (HttpURLConnection) gurl
connection.addRequestProperty("X-AppEngine-QueueName", "twitter"); .openConnection();
connection.addRequestProperty("context", context); connection.addRequestProperty("X-AppEngine-QueueName", "twitter");
InputStream i = connection.getInputStream(); connection.addRequestProperty("context", context);
String string = Utils.toStringAndClose(i); InputStream i = connection.getInputStream();
assert string.indexOf("Done!") >= 0 : string; String string = Utils.toStringAndClose(i);
connection.disconnect(); assert string.indexOf("Done!") >= 0 : string;
} connection.disconnect();
}
System.err.println("sleeping 10 seconds to allow for eventual consistency delay"); System.err.println("sleeping 10 seconds to allow for eventual consistency delay");
Thread.sleep(10000); Thread.sleep(10000);
for (BlobStoreContext<?, ?> context : contexts) { for (BlobStoreContext<?, ?> context : contexts) {
assert context.createInputStreamMap(container).size() > 0 : context.getEndPoint();
}
}
assert context.createInputStreamMap(container).size() > 0 : context.getEndPoint(); @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers")
} public void testSerial() throws InterruptedException, IOException {
} URL gurl = new URL(url, "/tweets/get");
InputStream i = gurl.openStream();
String string = Utils.toStringAndClose(i);
assert string.indexOf("Tweets in Clouds") >= 0 : string;
}
@Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3)
public void testSerial() throws InterruptedException, IOException { public void testParallel() throws InterruptedException, IOException {
URL gurl = new URL(url, "/tweets/get"); URL gurl = new URL(url, "/tweets/get");
InputStream i = gurl.openStream(); InputStream i = gurl.openStream();
String string = Utils.toStringAndClose(i); String string = Utils.toStringAndClose(i);
assert string.indexOf("Tweets in Clouds") >= 0 : string; assert string.indexOf("Tweets in Clouds") >= 0 : string;
} }
}
@Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3)
public void testParallel() throws InterruptedException, IOException {
URL gurl = new URL(url, "/tweets/get");
InputStream i = gurl.openStream();
String string = Utils.toStringAndClose(i);
assert string.indexOf("Tweets in Clouds") >= 0 : string;
}
}