updated tests to include containercount parameter

This commit is contained in:
Adrian Cole 2011-04-08 15:03:14 -07:00
parent b7e2f606c7
commit 5f43dbb6fa
3 changed files with 58 additions and 47 deletions

View File

@ -65,19 +65,20 @@ public class BaseBlobStoreIntegrationTest {
protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple"); protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple");
protected Map<String, String> fiveStrings = ImmutableMap.of("one", String.format(XML_STRING_FORMAT, "apple"), "two", protected Map<String, String> fiveStrings = ImmutableMap.of("one", String.format(XML_STRING_FORMAT, "apple"), "two",
String.format(XML_STRING_FORMAT, "bear"), "three", String.format(XML_STRING_FORMAT, "candy"), "four", String.format(XML_STRING_FORMAT, "bear"), "three", String.format(XML_STRING_FORMAT, "candy"), "four",
String.format(XML_STRING_FORMAT, "dogma"), "five", String.format(XML_STRING_FORMAT, "emma")); String.format(XML_STRING_FORMAT, "dogma"), "five", String.format(XML_STRING_FORMAT, "emma"));
protected Map<String, String> fiveStringsUnderPath = ImmutableMap.of("path/1", String.format(XML_STRING_FORMAT, protected Map<String, String> fiveStringsUnderPath = ImmutableMap.of("path/1",
"apple"), "path/2", String.format(XML_STRING_FORMAT, "bear"), "path/3", String.format(XML_STRING_FORMAT, String.format(XML_STRING_FORMAT, "apple"), "path/2", String.format(XML_STRING_FORMAT, "bear"), "path/3",
"candy"), "path/4", String.format(XML_STRING_FORMAT, "dogma"), "path/5", String.format(XML_STRING_FORMAT, String.format(XML_STRING_FORMAT, "candy"), "path/4", String.format(XML_STRING_FORMAT, "dogma"), "path/5",
"emma")); String.format(XML_STRING_FORMAT, "emma"));
public static long INCONSISTENCY_WINDOW = 10000; public static long INCONSISTENCY_WINDOW = 10000;
protected static volatile AtomicInteger containerIndex = new AtomicInteger(0); protected static volatile AtomicInteger containerIndex = new AtomicInteger(0);
protected volatile BlobStoreContext context; protected volatile BlobStoreContext context;
protected static volatile int containerCount = 10; protected static volatile int containerCount = Integer.parseInt(System.getProperty("test.blobstore.container-count",
"10"));
public static final String CONTAINER_PREFIX = System.getProperty("user.name") + "-blobstore"; public static final String CONTAINER_PREFIX = System.getProperty("user.name") + "-blobstore";
/** /**
* two test groups integration and live. * two test groups integration and live.
@ -95,7 +96,7 @@ public class BaseBlobStoreIntegrationTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private BlobStoreContext getCloudResources(ITestContext testContext) throws ClassNotFoundException, private BlobStoreContext getCloudResources(ITestContext testContext) throws ClassNotFoundException,
InstantiationException, IllegalAccessException, Exception { InstantiationException, IllegalAccessException, Exception {
String initializerClass = checkNotNull(System.getProperty("test.initializer"), "test.initializer"); String initializerClass = checkNotNull(System.getProperty("test.initializer"), "test.initializer");
Class<BaseTestInitializer> clazz = (Class<BaseTestInitializer>) Class.forName(initializerClass); Class<BaseTestInitializer> clazz = (Class<BaseTestInitializer>) Class.forName(initializerClass);
BaseTestInitializer initializer = clazz.newInstance(); BaseTestInitializer initializer = clazz.newInstance();
@ -128,7 +129,7 @@ public class BaseBlobStoreIntegrationTest {
private static volatile boolean initialized = false; private static volatile boolean initialized = false;
protected void createContainersSharedByAllThreads(BlobStoreContext context, ITestContext testContext) protected void createContainersSharedByAllThreads(BlobStoreContext context, ITestContext testContext)
throws Exception { throws Exception {
while (!initialized) { while (!initialized) {
synchronized (BaseBlobStoreIntegrationTest.class) { synchronized (BaseBlobStoreIntegrationTest.class) {
if (!initialized) { if (!initialized) {
@ -179,12 +180,12 @@ public class BaseBlobStoreIntegrationTest {
try { try {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Iterable<? extends StorageMetadata> testContainers = Iterables.filter(context.getBlobStore().list(), Iterable<? extends StorageMetadata> testContainers = Iterables.filter(context.getBlobStore().list(),
new Predicate<StorageMetadata>() { new Predicate<StorageMetadata>() {
public boolean apply(StorageMetadata input) { public boolean apply(StorageMetadata input) {
return (input.getType() == StorageType.CONTAINER || input.getType() == StorageType.FOLDER) return (input.getType() == StorageType.CONTAINER || input.getType() == StorageType.FOLDER)
&& input.getName().startsWith(CONTAINER_PREFIX.toLowerCase()); && input.getName().startsWith(CONTAINER_PREFIX.toLowerCase());
} }
}); });
for (StorageMetadata container : testContainers) { for (StorageMetadata container : testContainers) {
deleteContainerOrWarnIfUnable(context, container.getName()); deleteContainerOrWarnIfUnable(context, container.getName());
} }
@ -205,7 +206,7 @@ public class BaseBlobStoreIntegrationTest {
* we will try up to the inconsistency window to see if the assertion completes. * we will try up to the inconsistency window to see if the assertion completes.
*/ */
protected static void assertConsistencyAware(BlobStoreContext context, Runnable assertion) protected static void assertConsistencyAware(BlobStoreContext context, Runnable assertion)
throws InterruptedException { throws InterruptedException {
if (context.getConsistencyModel() == ConsistencyModel.STRICT) { if (context.getConsistencyModel() == ConsistencyModel.STRICT) {
assertion.run(); assertion.run();
return; return;
@ -231,7 +232,7 @@ public class BaseBlobStoreIntegrationTest {
} }
protected static void createContainerAndEnsureEmpty(BlobStoreContext context, final String containerName) protected static void createContainerAndEnsureEmpty(BlobStoreContext context, final String containerName)
throws InterruptedException { throws InterruptedException {
context.getBlobStore().createContainerInLocation(null, containerName); context.getBlobStore().createContainerInLocation(null, containerName);
if (context.getConsistencyModel() == ConsistencyModel.EVENTUAL) if (context.getConsistencyModel() == ConsistencyModel.EVENTUAL)
Thread.sleep(1000); Thread.sleep(1000);
@ -253,8 +254,8 @@ public class BaseBlobStoreIntegrationTest {
protected void add5BlobsUnderPathAnd5UnderRootToContainer(String sourceContainer) { protected void add5BlobsUnderPathAnd5UnderRootToContainer(String sourceContainer) {
for (Entry<String, String> entry : Iterables.concat(fiveStrings.entrySet(), fiveStringsUnderPath.entrySet())) { for (Entry<String, String> entry : Iterables.concat(fiveStrings.entrySet(), fiveStringsUnderPath.entrySet())) {
Blob sourceObject = context.getBlobStore().blobBuilder(entry.getKey()).payload(entry.getValue()).contentType( Blob sourceObject = context.getBlobStore().blobBuilder(entry.getKey()).payload(entry.getValue())
"text/xml").build(); .contentType("text/xml").build();
addBlobToContainer(sourceContainer, sourceObject); addBlobToContainer(sourceContainer, sourceObject);
} }
} }
@ -284,35 +285,14 @@ public class BaseBlobStoreIntegrationTest {
} }
protected void assertConsistencyAwareContainerSize(final String containerName, final int count) protected void assertConsistencyAwareContainerSize(final String containerName, final int count)
throws InterruptedException { throws InterruptedException {
assertConsistencyAware(new Runnable() { assertConsistencyAware(new Runnable() {
public void run() { public void run() {
try { try {
assert context.getBlobStore().countBlobs(containerName) == count : String.format( assert context.getBlobStore().countBlobs(containerName) == count : String.format(
"expected only %d values in %s: %s", count, containerName, ImmutableSet.copyOf(Iterables "expected only %d values in %s: %s", count, containerName, ImmutableSet.copyOf(Iterables
.transform(context.getBlobStore().list(containerName), .transform(context.getBlobStore().list(containerName),
new Function<StorageMetadata, String>() { new Function<StorageMetadata, String>() {
public String apply(StorageMetadata from) {
return from.getName();
}
})));
} catch (Exception e) {
Throwables.propagateIfPossible(e);
}
}
});
}
protected void assertConsistencyAwareBlobExists(final String containerName, final String name)
throws InterruptedException {
assertConsistencyAware(new Runnable() {
public void run() {
try {
assert context.getBlobStore().blobExists(containerName, name) : String.format(
"could not find %s in %s: %s", name, containerName, ImmutableSet.copyOf(Iterables.transform(
context.getBlobStore().list(containerName), new Function<StorageMetadata, String>() {
public String apply(StorageMetadata from) { public String apply(StorageMetadata from) {
return from.getName(); return from.getName();
@ -326,13 +306,34 @@ public class BaseBlobStoreIntegrationTest {
}); });
} }
protected void assertConsistencyAwareBlobExists(final String containerName, final String name)
throws InterruptedException {
assertConsistencyAware(new Runnable() {
public void run() {
try {
assert context.getBlobStore().blobExists(containerName, name) : String.format(
"could not find %s in %s: %s", name, containerName, ImmutableSet.copyOf(Iterables.transform(
context.getBlobStore().list(containerName), new Function<StorageMetadata, String>() {
public String apply(StorageMetadata from) {
return from.getName();
}
})));
} catch (Exception e) {
Throwables.propagateIfPossible(e);
}
}
});
}
protected void assertConsistencyAwareBlobDoesntExist(final String containerName, final String name) protected void assertConsistencyAwareBlobDoesntExist(final String containerName, final String name)
throws InterruptedException { throws InterruptedException {
assertConsistencyAware(new Runnable() { assertConsistencyAware(new Runnable() {
public void run() { public void run() {
try { try {
assert !context.getBlobStore().blobExists(containerName, name) : String.format("found %s in %s", name, assert !context.getBlobStore().blobExists(containerName, name) : String.format("found %s in %s", name,
containerName); containerName);
} catch (Exception e) { } catch (Exception e) {
Throwables.propagateIfPossible(e); Throwables.propagateIfPossible(e);
} }
@ -386,7 +387,7 @@ public class BaseBlobStoreIntegrationTest {
public void run() { public void run() {
try { try {
assert !context.getBlobStore().containerExists(containerName) : "container " + containerName assert !context.getBlobStore().containerExists(containerName) : "container " + containerName
+ " still exists"; + " still exists";
} catch (Exception e) { } catch (Exception e) {
propagateIfPossible(e); propagateIfPossible(e);
} }

View File

@ -40,6 +40,7 @@
<test.aws-s3.apiversion>2006-03-01</test.aws-s3.apiversion> <test.aws-s3.apiversion>2006-03-01</test.aws-s3.apiversion>
<test.aws-s3.identity>${test.aws.identity}</test.aws-s3.identity> <test.aws-s3.identity>${test.aws.identity}</test.aws-s3.identity>
<test.aws-s3.credential>${test.aws.credential}</test.aws-s3.credential> <test.aws-s3.credential>${test.aws.credential}</test.aws-s3.credential>
<test.blobstore.container-count>25</test.blobstore.container-count>
</properties> </properties>
<!-- temporary --> <!-- temporary -->
@ -150,6 +151,10 @@
<name>jclouds.blobstore.httpstream.md5</name> <name>jclouds.blobstore.httpstream.md5</name>
<value>${jclouds.blobstore.httpstream.md5}</value> <value>${jclouds.blobstore.httpstream.md5}</value>
</property> </property>
<property>
<name>test.blobstore.container-count</name>
<value>${test.blobstore.container-count}</value>
</property>
</systemProperties> </systemProperties>
</configuration> </configuration>
</execution> </execution>

View File

@ -40,6 +40,7 @@
<test.eucalyptus-partnercloud-s3.apiversion>2006-03-01</test.eucalyptus-partnercloud-s3.apiversion> <test.eucalyptus-partnercloud-s3.apiversion>2006-03-01</test.eucalyptus-partnercloud-s3.apiversion>
<test.eucalyptus-partnercloud-s3.identity>FIXME_IDENTITY</test.eucalyptus-partnercloud-s3.identity> <test.eucalyptus-partnercloud-s3.identity>FIXME_IDENTITY</test.eucalyptus-partnercloud-s3.identity>
<test.eucalyptus-partnercloud-s3.credential>FIXME_CREDENTIAL</test.eucalyptus-partnercloud-s3.credential> <test.eucalyptus-partnercloud-s3.credential>FIXME_CREDENTIAL</test.eucalyptus-partnercloud-s3.credential>
<test.blobstore.container-count>15</test.blobstore.container-count>
</properties> </properties>
<dependencies> <dependencies>
@ -136,6 +137,10 @@
<name>jclouds.blobstore.httpstream.md5</name> <name>jclouds.blobstore.httpstream.md5</name>
<value>${jclouds.blobstore.httpstream.md5}</value> <value>${jclouds.blobstore.httpstream.md5}</value>
</property> </property>
<property>
<name>test.blobstore.container-count</name>
<value>${test.blobstore.container-count}</value>
</property>
</systemProperties> </systemProperties>
</configuration> </configuration>
</execution> </execution>