made name a mandatory parameter of newBlob

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2612 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-06 17:54:41 +00:00
parent 183342d7f0
commit 2d3c1b6019
29 changed files with 123 additions and 92 deletions

View File

@ -88,8 +88,10 @@ public class BaseAtmosBlobStore {
.getClass().getName())); .getClass().getName()));
} }
public Blob newBlob() { public Blob newBlob(String name) {
return blobFactory.create(null); Blob blob = blobFactory.create(null);
blob.getMetadata().setName(name);
return blob;
} }
} }

View File

@ -75,7 +75,7 @@ public class AtmosBlobStoreContextBuilderTest {
assertEquals(context.getAsyncApi().getClass(), StubAtmosStorageAsyncClient.class); assertEquals(context.getAsyncApi().getClass(), StubAtmosStorageAsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), AtmosAsyncBlobStore.class); assertEquals(context.getAsyncBlobStore().getClass(), AtmosAsyncBlobStore.class);
assertEquals(context.getAsyncApi().newObject().getClass(), AtmosObjectImpl.class); assertEquals(context.getAsyncApi().newObject().getClass(), AtmosObjectImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob().getClass(), BlobImpl.class); assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id"); assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub")); assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub"));
} }

View File

@ -508,6 +508,55 @@ public interface InstanceClient {
* {@link InstanceState#STOPPING} to {@link InstanceState#STOPPED}</li> * {@link InstanceState#STOPPING} to {@link InstanceState#STOPPED}</li>
* </ol> * </ol>
* *
* The {@code blockDeviceMapping} option takes a value in the following format:
* <device-name>=<snapshot-id>[:<volume-size>[:<deleteOnTermination>]]
* <ol>
* <li>device-name - this is the device name as it should be exposed to the instance, for example
* /dev/sdb. This is the same as the device field specified in the AttachVolume call today. This
* field also serves as the key for the structure.</li>
* <li>snapshot-id - the ID of the EBS snapshot to be used when creating the volume. This field
* is optional. If it is not specified, the volume-size field must be present to create a blank
* volume of the specified size.</li>
* <li>volume-size - the size (GiBs) of the volume. This field is optional unless no snapshot-id
* is present. If a snapshot-id is present, the size must be equal to or larger than the
* snapshot's volume size.</li>
* <li>delete-on-termination - this indicates whether the volume should be deleted on
* termination. It defaults to ' true '.</li>
* </ol>
* <p/>
* Note that the device names between Linux and Windows differ. For Linux, ensure that your
* device name is in the form /dev/sd[a-z] . For example, /dev/sda , /dev/sdb and /dev/sdh are
* all valid device names.
* <p/>
* For Windows, the root device is still referred to as /dev/sda1 . For other devices, ensure
* that they are in the form /xvd[c-p] . For example, /xvde , /xvdf and /xvdp are all valid
* Windows device names.
* <p/>
* Here are a few extra examples on how this functionality can be used.
*
* <ol>
* <li>
* resize the root volume: @{code /dev/sda1=:100}</li>
* <li>
* don't delete the root volume: {@code /dev/sda1=:100:false}</li>
* <li>
* TODO: unverified: create and attach an additional volume at launch: {@code
* /dev/sdb=snap-e8a23d81,/dev/sdc=:200}
* <p/>
* The above example will create and attach the following EBS volumes at launch time:
* <ol>
* <li>
* /dev/sdb - a 10 GiBs EBS volume containing an ext3 file system; this is an Amazon shared
* snapshot.</li>
* <li>
* /dev/sdc - an empty 200 GiB EBS volume.</li>
* </ol>
* </li>
* <li>
* TODO: unverified: cresize the root partition of a Windows 2008 image and add an additional 100
* GiB device: {@code /dev/sda1=:100,/dev/xvdc=:100}</li>
* </ol>
*
* @param region * @param region
* Instances are tied to Availability Zones. However, the instance ID is tied to the * Instances are tied to Availability Zones. However, the instance ID is tied to the
* Region. * Region.

View File

@ -93,8 +93,10 @@ public class BaseS3BlobStore {
.getClass().getName())); .getClass().getName()));
} }
public Blob newBlob() { public Blob newBlob(String name) {
return blobFactory.create(null); Blob blob = blobFactory.create(null);
blob.getMetadata().setName(name);
return blob;
} }
} }

View File

@ -72,7 +72,7 @@ public class S3BlobStoreContextBuilderTest {
assertEquals(context.getAsyncApi().getClass(), StubS3AsyncClient.class); assertEquals(context.getAsyncApi().getClass(), StubS3AsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), S3AsyncBlobStore.class); assertEquals(context.getAsyncBlobStore().getClass(), S3AsyncBlobStore.class);
assertEquals(context.getAsyncApi().newS3Object().getClass(), S3ObjectImpl.class); assertEquals(context.getAsyncApi().newS3Object().getClass(), S3ObjectImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob().getClass(), BlobImpl.class); assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id"); assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://localhost/s3stub")); assertEquals(context.getEndPoint(), URI.create("https://localhost/s3stub"));
} }

View File

@ -58,8 +58,7 @@ public class MainApp {
BlobStore blobStore = context.getBlobStore(); BlobStore blobStore = context.getBlobStore();
blobStore.createContainer(containerName); blobStore.createContainer(containerName);
Blob blob = blobStore.newBlob(); Blob blob = blobStore.newBlob("test");
blob.getMetadata().setName("test");
blob.setPayload("testdata"); blob.setPayload("testdata");
blobStore.putBlob(containerName, blob); blobStore.putBlob(containerName, blob);

View File

@ -127,8 +127,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
try { try {
String objectKey = "key-testDeleteObjectImpl"; String objectKey = "key-testDeleteObjectImpl";
String objectValue = "test"; String objectValue = "test";
Blob blob = context.getAsyncBlobStore().newBlob(); Blob blob = context.getAsyncBlobStore().newBlob(objectKey);
blob.getMetadata().setName(objectKey);
blob.setPayload(objectValue); blob.setPayload(objectValue);
addBlobToContainer(bucketName, blob); addBlobToContainer(bucketName, blob);
@ -148,8 +147,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
String metadataName = "metadata-name-1"; String metadataName = "metadata-name-1";
String metadataValue = "metadata-value-1"; String metadataValue = "metadata-value-1";
Blob blob = context.getAsyncBlobStore().newBlob(); Blob blob = context.getAsyncBlobStore().newBlob(objectKey);
blob.getMetadata().setName(objectKey);
blob.setPayload(objectValue); blob.setPayload(objectValue);
blob.getMetadata().getUserMetadata().put(metadataName, metadataValue); blob.getMetadata().getUserMetadata().put(metadataName, metadataValue);
addBlobToContainer(bucketName, blob); addBlobToContainer(bucketName, blob);
@ -175,8 +173,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
String metadataName = "metadata-name-2"; String metadataName = "metadata-name-2";
String metadataValue = "metadata-value-2"; String metadataValue = "metadata-value-2";
Blob blob = context.getAsyncBlobStore().newBlob(); Blob blob = context.getAsyncBlobStore().newBlob(objectKey);
blob.getMetadata().setName(objectKey);
blob.setPayload(objectValue); blob.setPayload(objectValue);
blob.getMetadata().getUserMetadata().put(metadataName, metadataValue); blob.getMetadata().getUserMetadata().put(metadataName, metadataValue);
addBlobToContainer(bucketName, blob); addBlobToContainer(bucketName, blob);
@ -434,8 +431,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
String sourceMetadataValue = "souce-metadata-value"; String sourceMetadataValue = "souce-metadata-value";
String destinationMetadataValue = "destination-metadata-value"; String destinationMetadataValue = "destination-metadata-value";
Blob blob = context.getAsyncBlobStore().newBlob(); Blob blob = context.getAsyncBlobStore().newBlob(sourceObjectKey);
blob.getMetadata().setName(sourceObjectKey);
blob.setPayload(data); blob.setPayload(data);
blob.getMetadata().getUserMetadata().put(metadataName, sourceMetadataValue); blob.getMetadata().getUserMetadata().put(metadataName, sourceMetadataValue);
addBlobToContainer(bucketName, blob); addBlobToContainer(bucketName, blob);

View File

@ -66,9 +66,8 @@ public class BaseAzureBlobStore {
ClearListStrategy clearContainerStrategy, BlobPropertiesToBlobMetadata object2BlobMd, ClearListStrategy clearContainerStrategy, BlobPropertiesToBlobMetadata object2BlobMd,
AzureBlobToBlob object2Blob, BlobToAzureBlob blob2Object, AzureBlobToBlob object2Blob, BlobToAzureBlob blob2Object,
ListOptionsToListBlobsOptions container2ContainerListOptions, ListOptionsToListBlobsOptions container2ContainerListOptions,
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToHttpGetOptions blob2ObjectGetOptions, GetDirectoryStrategy getDirectoryStrategy,
GetDirectoryStrategy getDirectoryStrategy, MkdirStrategy mkdirStrategy, MkdirStrategy mkdirStrategy, ContainerToResourceMetadata container2ResourceMd,
ContainerToResourceMetadata container2ResourceMd,
ListBlobsResponseToResourceList container2ResourceList, ExecutorService service) { ListBlobsResponseToResourceList container2ResourceList, ExecutorService service) {
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
@ -81,8 +80,7 @@ public class BaseAzureBlobStore {
this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions, this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,
"container2ContainerListOptions"); "container2ContainerListOptions");
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, "getDirectoryStrategy");
"getDirectoryStrategy");
this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy"); this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy");
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
this.container2ResourceList = checkNotNull(container2ResourceList, "container2ResourceList"); this.container2ResourceList = checkNotNull(container2ResourceList, "container2ResourceList");
@ -94,8 +92,10 @@ public class BaseAzureBlobStore {
.getClass().getName())); .getClass().getName()));
} }
public Blob newBlob() { public Blob newBlob(String name) {
return blobFactory.create(null); Blob blob = blobFactory.create(null);
blob.getMetadata().setName(name);
return blob;
} }
} }

View File

@ -56,17 +56,16 @@ public class AzureBlobStoreContextBuilderTest {
public void testNewBuilder() { public void testNewBuilder() {
AzureBlobStoreContextBuilder builder = newBuilder(); AzureBlobStoreContextBuilder builder = newBuilder();
assertEquals(builder.getProperties().getProperty(PROPERTY_USER_METADATA_PREFIX), assertEquals(builder.getProperties().getProperty(PROPERTY_USER_METADATA_PREFIX), "x-ms-meta-");
"x-ms-meta-"); assertEquals(builder.getProperties().getProperty(
assertEquals(builder.getProperties().getProperty(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT), AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT), "id");
"id"); assertEquals(builder.getProperties().getProperty(
assertEquals(builder.getProperties().getProperty(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY), AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY), "secret");
"secret");
} }
private AzureBlobStoreContextBuilder newBuilder() { private AzureBlobStoreContextBuilder newBuilder() {
return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder("id", return new AzureBlobStoreContextBuilder(new AzureBlobPropertiesBuilder("id", "secret")
"secret").build()).withModules(new AzureBlobStubClientModule()); .build()).withModules(new AzureBlobStubClientModule());
} }
public void testBuildContext() { public void testBuildContext() {
@ -75,15 +74,16 @@ public class AzureBlobStoreContextBuilderTest {
assertEquals(context.getAsyncApi().getClass(), StubAzureBlobAsyncClient.class); assertEquals(context.getAsyncApi().getClass(), StubAzureBlobAsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), AzureAsyncBlobStore.class); assertEquals(context.getAsyncBlobStore().getClass(), AzureAsyncBlobStore.class);
assertEquals(context.getAsyncApi().newBlob().getClass(), AzureBlobImpl.class); assertEquals(context.getAsyncApi().newBlob().getClass(), AzureBlobImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob().getClass(), BlobImpl.class); assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id"); assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub")); assertEquals(context.getEndPoint(), URI.create("https://localhost/azurestub"));
} }
public void testBuildInjector() { public void testBuildInjector() {
Injector i = newBuilder().buildInjector(); Injector i = newBuilder().buildInjector();
assert i.getInstance(Key.get(new TypeLiteral<BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>>() { assert i.getInstance(Key
})) != null; .get(new TypeLiteral<BlobStoreContext<AzureBlobAsyncClient, AzureBlobClient>>() {
})) != null;
assert i.getInstance(AzureBlob.class) != null; assert i.getInstance(AzureBlob.class) != null;
assert i.getInstance(Blob.class) != null; assert i.getInstance(Blob.class) != null;
} }

View File

@ -35,7 +35,7 @@ import org.jclouds.blobstore.options.ListContainerOptions;
*/ */
public interface AsyncBlobStore { public interface AsyncBlobStore {
Blob newBlob(); Blob newBlob(String name);
/** /**
* Lists all root-level resources available to the account. * Lists all root-level resources available to the account.

View File

@ -34,7 +34,7 @@ import com.google.inject.ImplementedBy;
@ImplementedBy(BlobMapImpl.class) @ImplementedBy(BlobMapImpl.class)
public interface BlobMap extends ListableMap<String, Blob> { public interface BlobMap extends ListableMap<String, Blob> {
Blob newBlob(); Blob newBlob(String name);
public static interface Factory { public static interface Factory {
BlobMap create(String containerName, ListContainerOptions listOptions); BlobMap create(String containerName, ListContainerOptions listOptions);

View File

@ -33,7 +33,7 @@ import org.jclouds.blobstore.options.ListContainerOptions;
*/ */
public interface BlobStore { public interface BlobStore {
Blob newBlob(); Blob newBlob(String name);
/** /**
* Lists all root-level resources available to the account. * Lists all root-level resources available to the account.

View File

@ -213,8 +213,8 @@ public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
}); });
} }
public Blob newBlob() { public Blob newBlob(String name) {
return connection.newBlob(); return connection.newBlob(name);
} }
} }

View File

@ -225,8 +225,7 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
try { try {
Set<Future<String>> puts = Sets.newHashSet(); Set<Future<String>> puts = Sets.newHashSet();
for (Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) { for (Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) {
Blob object = connection.newBlob(); Blob object = connection.newBlob(prefixer.apply(entry.getKey()));
object.getMetadata().setName(prefixer.apply(entry.getKey()));
object.setPayload(Payloads.newPayload(entry.getValue())); object.setPayload(Payloads.newPayload(entry.getValue()));
object.generateMD5(); object.generateMD5();
puts.add(connection.putBlob(containerName, object)); puts.add(connection.putBlob(containerName, object));
@ -286,11 +285,10 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
* @see S3Client#put(String, Blob) * @see S3Client#put(String, Blob)
*/ */
@VisibleForTesting @VisibleForTesting
InputStream putInternal(String s, Payload payload) { InputStream putInternal(String name, Payload payload) {
Blob object = connection.newBlob(); Blob object = connection.newBlob(prefixer.apply(name));
object.getMetadata().setName(prefixer.apply(s));
try { try {
InputStream returnVal = containsKey(s) ? get(s) : null; InputStream returnVal = containsKey(name) ? get(name) : null;
object.setPayload(payload); object.setPayload(payload);
object.generateMD5(); object.generateMD5();
connection.putBlob(containerName, object).get(requestTimeoutMilliseconds, connection.putBlob(containerName, object).get(requestTimeoutMilliseconds,

View File

@ -58,8 +58,7 @@ public class MarkerFileMkdirStrategy implements MkdirStrategy {
try { try {
if (!connection.directoryExists(containerName, directory).get(requestTimeoutMilliseconds, if (!connection.directoryExists(containerName, directory).get(requestTimeoutMilliseconds,
TimeUnit.MILLISECONDS)) { TimeUnit.MILLISECONDS)) {
Blob blob = connection.newBlob(); Blob blob = connection.newBlob(directory + directorySuffix);
blob.getMetadata().setName(directory + directorySuffix);
blob.setPayload(""); blob.setPayload("");
blob.getMetadata().setContentType("application/directory"); blob.getMetadata().setContentType("application/directory");
connection.putBlob(containerName, blob).get(requestTimeoutMilliseconds, connection.putBlob(containerName, blob).get(requestTimeoutMilliseconds,

View File

@ -37,7 +37,7 @@ import org.jclouds.util.Utils;
public class BlobStoreUtils { public class BlobStoreUtils {
public static Blob newBlob(BlobStore blobStore, ResourceMetadata blobMeta) { public static Blob newBlob(BlobStore blobStore, ResourceMetadata blobMeta) {
Blob blob = blobStore.newBlob(); Blob blob = blobStore.newBlob(blobMeta.getName());
if (blobMeta instanceof BlobMetadata) { if (blobMeta instanceof BlobMetadata) {
blob.getMetadata().setContentMD5(((BlobMetadata) blobMeta).getContentMD5()); blob.getMetadata().setContentMD5(((BlobMetadata) blobMeta).getContentMD5());
blob.getMetadata().setContentType(((BlobMetadata) blobMeta).getContentType()); blob.getMetadata().setContentType(((BlobMetadata) blobMeta).getContentType());
@ -46,17 +46,10 @@ public class BlobStoreUtils {
blob.getMetadata().setId(blobMeta.getId()); blob.getMetadata().setId(blobMeta.getId());
blob.getMetadata().setLastModified(blobMeta.getLastModified()); blob.getMetadata().setLastModified(blobMeta.getLastModified());
blob.getMetadata().setLocation(blobMeta.getLocation()); blob.getMetadata().setLocation(blobMeta.getLocation());
blob.getMetadata().setName(blobMeta.getName());
blob.getMetadata().setUserMetadata(blobMeta.getUserMetadata()); blob.getMetadata().setUserMetadata(blobMeta.getUserMetadata());
return blob; return blob;
} }
public static Blob newBlob(BlobStore blobStore, String name) {
Blob blob = blobStore.newBlob();
blob.getMetadata().setName(name);
return blob;
}
public static String parseContainerFromPath(String path) { public static String parseContainerFromPath(String path) {
String container = path; String container = path;
if (path.indexOf('/') != -1) if (path.indexOf('/') != -1)

View File

@ -296,7 +296,7 @@ public class BaseBlobIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<
@Test(groups = { "integration", "live" }, dataProvider = "putTests") @Test(groups = { "integration", "live" }, dataProvider = "putTests")
public void testPutObject(String key, String type, Object content, Object realObject) public void testPutObject(String key, String type, Object content, Object realObject)
throws InterruptedException, IOException { throws InterruptedException, IOException {
Blob object = newBlob(key); Blob object = context.getBlobStore().newBlob(key);
object.getMetadata().setContentType(type); object.getMetadata().setContentType(type);
object.setPayload(Payloads.newPayload(content)); object.setPayload(Payloads.newPayload(content));
if (content instanceof InputStream) { if (content instanceof InputStream) {
@ -318,7 +318,7 @@ public class BaseBlobIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<
public void testMetadata() throws InterruptedException { public void testMetadata() throws InterruptedException {
String key = "hello"; String key = "hello";
Blob object = newBlob(key); Blob object = context.getBlobStore().newBlob(key);
object.setPayload(TEST_STRING); object.setPayload(TEST_STRING);
object.getMetadata().setContentType("text/plain"); object.getMetadata().setContentType("text/plain");
object.getMetadata().setSize(new Long(TEST_STRING.length())); object.getMetadata().setSize(new Long(TEST_STRING.length()));

View File

@ -65,7 +65,7 @@ public class BaseBlobLiveTest<A, S> extends BaseBlobStoreIntegrationTest<A, S> {
int length = connection.getContentLength(); int length = connection.getContentLength();
InputStream input = connection.getInputStream(); InputStream input = connection.getInputStream();
Blob object = newBlob(key); Blob object = context.getBlobStore().newBlob(key);
object.setPayload(input); object.setPayload(input);
object.setContentLength(length); object.setContentLength(length);
object.getMetadata().setContentMD5(md5); object.getMetadata().setContentMD5(md5);

View File

@ -129,7 +129,7 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
try { try {
Map<String, Blob> map = createMap(context, bucketName); Map<String, Blob> map = createMap(context, bucketName);
putStringWithMD5(map, "one", "apple"); putStringWithMD5(map, "one", "apple");
Blob object = newBlob("one"); Blob object = context.getBlobStore().newBlob("one");
object.setPayload("apple"); object.setPayload("apple");
object.generateMD5(); object.generateMD5();
assertConsistencyAwareContainsValue(map, object); assertConsistencyAwareContainsValue(map, object);
@ -157,7 +157,7 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
String bucketName = getContainerName(); String bucketName = getContainerName();
try { try {
Map<String, Blob> map = createMap(context, bucketName); Map<String, Blob> map = createMap(context, bucketName);
Blob object = newBlob("one"); Blob object = context.getBlobStore().newBlob("one");
object.setPayload(Utils.toInputStream("apple")); object.setPayload(Utils.toInputStream("apple"));
object.generateMD5(); object.generateMD5();
Blob old = map.put(object.getMetadata().getName(), object); Blob old = map.put(object.getMetadata().getName(), object);
@ -178,7 +178,7 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
Map<String, Blob> map = createMap(context, bucketName); Map<String, Blob> map = createMap(context, bucketName);
Map<String, Blob> newMap = new HashMap<String, Blob>(); Map<String, Blob> newMap = new HashMap<String, Blob>();
for (String key : fiveInputs.keySet()) { for (String key : fiveInputs.keySet()) {
Blob object = newBlob(key); Blob object = context.getBlobStore().newBlob(key);
object.setPayload(fiveInputs.get(key)); object.setPayload(fiveInputs.get(key));
object.setContentLength(new Long(fiveBytes.get(key).length)); object.setContentLength(new Long(fiveBytes.get(key).length));
newMap.put(key, object); newMap.put(key, object);
@ -194,7 +194,7 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
@Override @Override
protected void putStringWithMD5(Map<String, Blob> map, String key, String value) { protected void putStringWithMD5(Map<String, Blob> map, String key, String value) {
Blob object = newBlob(key); Blob object = context.getBlobStore().newBlob(key);
object.setPayload(value); object.setPayload(value);
object.generateMD5(); object.generateMD5();
map.put(key, object); map.put(key, object);
@ -203,7 +203,7 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
protected void putFiveStrings(Map<String, Blob> map) { protected void putFiveStrings(Map<String, Blob> map) {
Map<String, Blob> newMap = new HashMap<String, Blob>(); Map<String, Blob> newMap = new HashMap<String, Blob>();
for (Map.Entry<String, String> entry : fiveStrings.entrySet()) { for (Map.Entry<String, String> entry : fiveStrings.entrySet()) {
Blob object = newBlob(entry.getKey()); Blob object = context.getBlobStore().newBlob(entry.getKey());
object.setPayload(entry.getValue()); object.setPayload(entry.getValue());
newMap.put(entry.getKey(), object); newMap.put(entry.getKey(), object);
} }
@ -213,7 +213,7 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
protected void putFiveStringsUnderPath(Map<String, Blob> map) { protected void putFiveStringsUnderPath(Map<String, Blob> map) {
Map<String, Blob> newMap = new HashMap<String, Blob>(); Map<String, Blob> newMap = new HashMap<String, Blob>();
for (Map.Entry<String, String> entry : fiveStringsUnderPath.entrySet()) { for (Map.Entry<String, String> entry : fiveStringsUnderPath.entrySet()) {
Blob object = newBlob(entry.getKey()); Blob object = context.getBlobStore().newBlob(entry.getKey());
object.setPayload(entry.getValue()); object.setPayload(entry.getValue());
newMap.put(entry.getKey(), object); newMap.put(entry.getKey(), object);
} }

View File

@ -125,12 +125,6 @@ public class BaseBlobStoreIntegrationTest<A, S> {
private static volatile boolean initialized = false; private static volatile boolean initialized = false;
protected Blob newBlob(String key) {
Blob object = context.getBlobStore().newBlob();
object.getMetadata().setName(key);
return object;
}
protected void createContainersSharedByAllThreads(BlobStoreContext<A, S> context, protected void createContainersSharedByAllThreads(BlobStoreContext<A, S> context,
ITestContext testContext) throws Exception { ITestContext testContext) throws Exception {
while (!initialized) { while (!initialized) {
@ -256,7 +250,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
} }
protected String addBlobToContainer(String sourceContainer, String key) { protected String addBlobToContainer(String sourceContainer, String key) {
Blob sourceObject = newBlob(key); Blob sourceObject = context.getBlobStore().newBlob(key);
sourceObject.getMetadata().setContentType("text/xml"); sourceObject.getMetadata().setContentType("text/xml");
sourceObject.setPayload(TEST_STRING); sourceObject.setPayload(TEST_STRING);
return addBlobToContainer(sourceContainer, sourceObject); return addBlobToContainer(sourceContainer, sourceObject);
@ -265,7 +259,7 @@ public class BaseBlobStoreIntegrationTest<A, S> {
protected void add5BlobsUnderPathAnd5UnderRootToContainer(String sourceContainer) { protected void add5BlobsUnderPathAnd5UnderRootToContainer(String sourceContainer) {
for (Entry<String, String> entry : Iterables.concat(fiveStrings.entrySet(), for (Entry<String, String> entry : Iterables.concat(fiveStrings.entrySet(),
fiveStringsUnderPath.entrySet())) { fiveStringsUnderPath.entrySet())) {
Blob sourceObject = newBlob(entry.getKey()); Blob sourceObject = context.getBlobStore().newBlob(entry.getKey());
sourceObject.getMetadata().setContentType("text/xml"); sourceObject.getMetadata().setContentType("text/xml");
sourceObject.setPayload(entry.getValue()); sourceObject.setPayload(entry.getValue());
addBlobToContainer(sourceContainer, sourceObject); addBlobToContainer(sourceContainer, sourceObject);

View File

@ -197,7 +197,7 @@ public class BaseContainerIntegrationTest<A, S> extends BaseBlobStoreIntegration
protected void addAlphabetUnderRoot(String containerName) throws InterruptedException { protected void addAlphabetUnderRoot(String containerName) throws InterruptedException {
for (char letter = 'a'; letter <= 'z'; letter++) { for (char letter = 'a'; letter <= 'z'; letter++) {
Blob blob = newBlob(letter + ""); Blob blob = context.getBlobStore().newBlob(letter + "");
blob.setPayload(letter + "content"); blob.setPayload(letter + "content");
context.getBlobStore().putBlob(containerName, blob); context.getBlobStore().putBlob(containerName, blob);
} }
@ -205,7 +205,7 @@ public class BaseContainerIntegrationTest<A, S> extends BaseBlobStoreIntegration
protected void add15UnderRoot(String containerName) throws InterruptedException { protected void add15UnderRoot(String containerName) throws InterruptedException {
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
Blob blob = newBlob(i + ""); Blob blob = context.getBlobStore().newBlob(i + "");
blob.setPayload(i + "content"); blob.setPayload(i + "content");
context.getBlobStore().putBlob(containerName, blob); context.getBlobStore().putBlob(containerName, blob);
} }
@ -214,7 +214,7 @@ public class BaseContainerIntegrationTest<A, S> extends BaseBlobStoreIntegration
protected void addTenObjectsUnderPrefix(String containerName, String prefix) protected void addTenObjectsUnderPrefix(String containerName, String prefix)
throws InterruptedException { throws InterruptedException {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
Blob blob = newBlob(prefix + "/" + i); Blob blob = context.getBlobStore().newBlob(prefix + "/" + i);
blob.setPayload(i + "content"); blob.setPayload(i + "content");
context.getBlobStore().putBlob(containerName, blob); context.getBlobStore().putBlob(containerName, blob);
} }

View File

@ -681,8 +681,10 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
}); });
} }
public Blob newBlob() { public Blob newBlob(String name) {
return blobProvider.create(null); Blob blob = blobProvider.create(null);
blob.getMetadata().setName(name);
return blob;
} }
} }

View File

@ -61,9 +61,8 @@ public class StoreTweetsController extends HttpServlet {
} }
public Blob apply(Status from) { public Blob apply(Status from) {
Blob to = map.newBlob(); Blob to = map.newBlob(from.getId() + "");
to.getMetadata().setContentType(MediaType.TEXT_PLAIN); to.getMetadata().setContentType(MediaType.TEXT_PLAIN);
to.getMetadata().setName(from.getId() + "");
to.setPayload(from.getText()); to.setPayload(from.getText());
to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME,
from.getUser().getScreenName()); from.getUser().getScreenName());

View File

@ -54,8 +54,7 @@ public class AddTweetsControllerTest {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder() BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext(); .buildContext();
context.getAsyncBlobStore().createContainer(container).get(); context.getAsyncBlobStore().createContainer(container).get();
Blob blob = context.getAsyncBlobStore().newBlob(); Blob blob = context.getAsyncBlobStore().newBlob("1");
blob.getMetadata().setName("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
blob.setPayload("I love beans!"); blob.setPayload("I love beans!");
context.getAsyncBlobStore().putBlob(container, blob).get(); context.getAsyncBlobStore().putBlob(container, blob).get();

View File

@ -50,8 +50,7 @@ public class KeyToStoredTweetStatusTest {
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
BlobMap map = createMap(); BlobMap map = createMap();
Blob blob = map.newBlob(); Blob blob = map.newBlob("1");
blob.getMetadata().setName("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
blob.setPayload("I love beans!"); blob.setPayload("I love beans!");
map.put("1", blob); map.put("1", blob);

View File

@ -51,8 +51,7 @@ public class ServiceToStoredTweetStatusesTest {
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder() BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
.buildContext(); .buildContext();
context.getAsyncBlobStore().createContainer(container).get(); context.getAsyncBlobStore().createContainer(container).get();
Blob blob = context.getAsyncBlobStore().newBlob(); Blob blob = context.getAsyncBlobStore().newBlob("1");
blob.getMetadata().setName("1");
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
blob.setPayload("I love beans!"); blob.setPayload("I love beans!");
context.getAsyncBlobStore().putBlob(container, blob).get(); context.getAsyncBlobStore().putBlob(container, blob).get();

View File

@ -81,8 +81,7 @@ public class BaseCloudFilesBlobStore {
this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions, this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,
"container2ContainerListOptions"); "container2ContainerListOptions");
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, "getDirectoryStrategy");
"getDirectoryStrategy");
this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy"); this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy");
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
this.container2ResourceList = checkNotNull(container2ResourceList, "container2ResourceList"); this.container2ResourceList = checkNotNull(container2ResourceList, "container2ResourceList");
@ -94,8 +93,10 @@ public class BaseCloudFilesBlobStore {
.getClass().getName())); .getClass().getName()));
} }
public Blob newBlob() { public Blob newBlob(String name) {
return blobFactory.create(null); Blob blob = blobFactory.create(null);
blob.getMetadata().setName(name);
return blob;
} }
} }

View File

@ -78,7 +78,7 @@ public class CloudFilesBlobStoreContextBuilderTest {
assertEquals(context.getAsyncApi().getClass(), StubCloudFilesAsyncClient.class); assertEquals(context.getAsyncApi().getClass(), StubCloudFilesAsyncClient.class);
assertEquals(context.getAsyncBlobStore().getClass(), CloudFilesAsyncBlobStore.class); assertEquals(context.getAsyncBlobStore().getClass(), CloudFilesAsyncBlobStore.class);
assertEquals(context.getAsyncApi().newCFObject().getClass(), CFObjectImpl.class); assertEquals(context.getAsyncApi().newCFObject().getClass(), CFObjectImpl.class);
assertEquals(context.getAsyncBlobStore().newBlob().getClass(), BlobImpl.class); assertEquals(context.getAsyncBlobStore().newBlob(null).getClass(), BlobImpl.class);
assertEquals(context.getAccount(), "id"); assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("http://localhost/rackspacestub/cloudfiles")); assertEquals(context.getEndPoint(), URI.create("http://localhost/rackspacestub/cloudfiles"));
} }

View File

@ -246,8 +246,8 @@ public class BlobStoreFileObject extends AbstractFileObject {
return new BlobStoreOutputStream(file, getBlobStore(), BlobStoreUtils.newBlob( return new BlobStoreOutputStream(file, getBlobStore(), BlobStoreUtils.newBlob(
getBlobStore(), metadata)); getBlobStore(), metadata));
} else { } else {
return new BlobStoreOutputStream(file, getBlobStore(), BlobStoreUtils.newBlob( return new BlobStoreOutputStream(file, getBlobStore(), getBlobStore().newBlob(
getBlobStore(), getNameTrimLeadingSlashes())); getNameTrimLeadingSlashes()));
} }
} }