mirror of https://github.com/apache/jclouds.git
Issue 656: failing test, demonstrating failures when non-default aws-s3 location is specified
This commit is contained in:
parent
db40facb2d
commit
1b2eb74604
|
@ -24,8 +24,8 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
@ -43,6 +43,7 @@ import org.jclouds.blobstore.domain.Blob;
|
|||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageType;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.AfterClass;
|
||||
|
@ -337,6 +338,22 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest<BlobStoreCont
|
|||
});
|
||||
}
|
||||
|
||||
protected void assertConsistencyAwareBlobInLocation(final String containerName, final String blobName, final Location loc)
|
||||
throws InterruptedException {
|
||||
assertConsistencyAware(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Location actualLoc = view.getBlobStore().getBlob(containerName, blobName).getMetadata().getLocation();
|
||||
|
||||
assert loc.equals(actualLoc) : String.format(
|
||||
"blob %s in %s, in location %s instead of %s", blobName, containerName, actualLoc, loc);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getContainerName() throws InterruptedException {
|
||||
String containerName = containerNames.poll(30, TimeUnit.SECONDS);
|
||||
assert containerName != null : "unable to get a container for the test";
|
||||
|
|
|
@ -18,16 +18,25 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.blobstore.config;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.aws.s3.blobstore.AWSS3AsyncBlobStore;
|
||||
import org.jclouds.aws.s3.blobstore.AWSS3BlobStore;
|
||||
import org.jclouds.aws.s3.blobstore.strategy.AsyncMultipartUploadStrategy;
|
||||
import org.jclouds.aws.s3.blobstore.strategy.MultipartUploadStrategy;
|
||||
import org.jclouds.aws.s3.blobstore.strategy.internal.ParallelMultipartUploadStrategy;
|
||||
import org.jclouds.aws.s3.blobstore.strategy.internal.SequentialMultipartUploadStrategy;
|
||||
import org.jclouds.cache.RetryingCacheLoaderDecorator;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.s3.S3Client;
|
||||
import org.jclouds.s3.blobstore.S3AsyncBlobStore;
|
||||
import org.jclouds.s3.blobstore.S3BlobStore;
|
||||
import org.jclouds.s3.blobstore.config.S3BlobStoreContextModule;
|
||||
import org.jclouds.s3.domain.AccessControlList;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
|
@ -45,5 +54,23 @@ public class AWSS3BlobStoreContextModule extends S3BlobStoreContextModule {
|
|||
bind(MultipartUploadStrategy.class).to(SequentialMultipartUploadStrategy.class);
|
||||
bind(AsyncMultipartUploadStrategy.class).to(ParallelMultipartUploadStrategy.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected LoadingCache<String, AccessControlList> bucketAcls(final S3Client client) {
|
||||
CacheLoader<String, AccessControlList> loader = RetryingCacheLoaderDecorator.newDecorator()
|
||||
.on(ResourceNotFoundException.class).exponentiallyBackoff()
|
||||
.decorate(
|
||||
new CacheLoader<String, AccessControlList>() {
|
||||
@Override
|
||||
public AccessControlList load(String bucketName) {
|
||||
return client.getBucketACL(bucketName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "getBucketAcl()";
|
||||
}
|
||||
});
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(loader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,23 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.blobstore.integration;
|
||||
|
||||
import static org.jclouds.blobstore.options.CreateContainerOptions.Builder.publicRead;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.s3.blobstore.integration.S3ContainerLiveTest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -29,4 +43,50 @@ public class AWSS3ContainerLiveTest extends S3ContainerLiveTest {
|
|||
public AWSS3ContainerLiveTest() {
|
||||
provider = "aws-s3";
|
||||
}
|
||||
|
||||
@Test(groups = { "live" })
|
||||
public void testCreateBlobInLocation() throws InterruptedException, MalformedURLException, IOException {
|
||||
String payload = "my data";
|
||||
runCreateContainerInLocation(payload);
|
||||
}
|
||||
|
||||
@Test(groups = { "live" })
|
||||
public void testCreateBigBlobInLocation() throws InterruptedException, MalformedURLException, IOException {
|
||||
String payload = Strings.repeat("a", 1024*1024); // 1MB
|
||||
runCreateContainerInLocation(payload);
|
||||
}
|
||||
|
||||
private void runCreateContainerInLocation(String payload) throws InterruptedException, MalformedURLException, IOException {
|
||||
String blobName = "hello";
|
||||
BlobStore blobStore = view.getBlobStore();
|
||||
final String containerName = getScratchContainerName();
|
||||
try {
|
||||
String locationId = "EU";
|
||||
Location location = findLocation(blobStore, locationId);
|
||||
blobStore.createContainerInLocation(location, containerName, publicRead());
|
||||
blobStore.putBlob(containerName, blobStore.blobBuilder(blobName).payload(payload).build());
|
||||
|
||||
assertConsistencyAwareContainerSize(containerName, 1);
|
||||
|
||||
BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, blobName);
|
||||
assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), payload);
|
||||
|
||||
assertConsistencyAwareBlobInLocation(containerName, blobName, location);
|
||||
|
||||
} finally {
|
||||
// this container is now public, so we can't reuse it directly
|
||||
recycleContainer(containerName);
|
||||
}
|
||||
}
|
||||
|
||||
private Location findLocation(BlobStore blobStore, String id) {
|
||||
Set<? extends Location> locs = blobStore.listAssignableLocations();
|
||||
for (Location loc : locs) {
|
||||
if (loc.getId().equals(id)) {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
throw new NoSuchElementException("No location found with id '"+id+"'; contenders were "+locs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue