mirror of https://github.com/apache/jclouds.git
Issue 462: corrected semantics of BlobMap when using inDirectory and added BlobBuilder
This commit is contained in:
parent
5df062ba47
commit
20c23e7962
|
@ -36,7 +36,7 @@ import com.google.common.base.Function;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ObjectToBlob implements Function<AtmosObject, Blob> {
|
public class ObjectToBlob implements Function<AtmosObject, Blob> {
|
||||||
private final Blob.Factory blobFactory;
|
private final Factory blobFactory;
|
||||||
private final ObjectToBlobMetadata object2BlobMd;
|
private final ObjectToBlobMetadata object2BlobMd;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
|
@ -129,10 +129,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FilesystemAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto,
|
protected FilesystemAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto,
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
HttpGetOptionsListToGetOptions httpGetOptionsConverter, IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
Factory blobFactory, BlobUtils blobUtils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
Supplier<Location> defaultLocation, @Memoized Supplier<Set<? extends Location>> locations,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, FilesystemStorageStrategy storageStrategy) {
|
FilesystemStorageStrategy storageStrategy) {
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
super(context, blobUtils, service, defaultLocation, locations);
|
||||||
// super(context, blobUtils, service, null, null);
|
// super(context, blobUtils, service, null, null);
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
|
@ -225,8 +225,8 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
|
|
||||||
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix != null ? prefix : null, delimiter)));
|
contents = newTreeSet(filter(contents, new DelimiterFilter(prefix != null ? prefix : null, delimiter)));
|
||||||
|
|
||||||
Iterables.<StorageMetadata> addAll(contents, transform(commonPrefixes,
|
Iterables.<StorageMetadata> addAll(contents,
|
||||||
new Function<String, StorageMetadata>() {
|
transform(commonPrefixes, new Function<String, StorageMetadata>() {
|
||||||
public StorageMetadata apply(String o) {
|
public StorageMetadata apply(String o) {
|
||||||
MutableStorageMetadata md = new MutableStorageMetadataImpl();
|
MutableStorageMetadata md = new MutableStorageMetadataImpl();
|
||||||
md.setType(StorageType.RELATIVE_PATH);
|
md.setType(StorageType.RELATIVE_PATH);
|
||||||
|
@ -330,7 +330,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Path("{container}")
|
@Path("{container}")
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
||||||
@PathParam("container") @ParamValidators( { FilesystemContainerNameValidator.class }) String name) {
|
@PathParam("container") @ParamValidators({ FilesystemContainerNameValidator.class }) String name) {
|
||||||
boolean result = storageStrategy.createContainer(name);
|
boolean result = storageStrategy.createContainer(name);
|
||||||
return immediateFuture(result);
|
return immediateFuture(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,33 +19,37 @@
|
||||||
|
|
||||||
package org.jclouds.filesystem.strategy.internal;
|
package org.jclouds.filesystem.strategy.internal;
|
||||||
|
|
||||||
import org.jclouds.rest.annotations.ParamValidators;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||||
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
|
||||||
import org.jclouds.io.Payload;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import java.io.IOException;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import java.io.File;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.name.Named;
|
|
||||||
|
|
||||||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.rest.annotations.ParamValidators;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.name.Named;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -60,21 +64,20 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
protected final Blob.Factory blobFactory;
|
protected final Provider<BlobBuilder> blobBuilders;
|
||||||
protected final String baseDirectory;
|
protected final String baseDirectory;
|
||||||
protected final FilesystemContainerNameValidator filesystemContainerNameValidator;
|
protected final FilesystemContainerNameValidator filesystemContainerNameValidator;
|
||||||
protected final FilesystemBlobKeyValidator filesystemBlobKeyValidator;
|
protected final FilesystemBlobKeyValidator filesystemBlobKeyValidator;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FilesystemStorageStrategyImpl(
|
protected FilesystemStorageStrategyImpl(Provider<BlobBuilder> blobBuilders,
|
||||||
Blob.Factory blobFactory,
|
|
||||||
@Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
|
@Named(FilesystemConstants.PROPERTY_BASEDIR) String baseDir,
|
||||||
FilesystemContainerNameValidator filesystemContainerNameValidator,
|
FilesystemContainerNameValidator filesystemContainerNameValidator,
|
||||||
FilesystemBlobKeyValidator filesystemBlobKeyValidator) {
|
FilesystemBlobKeyValidator filesystemBlobKeyValidator) {
|
||||||
this.blobFactory = checkNotNull(blobFactory, "filesystem storage strategy blobfactory");
|
this.blobBuilders = checkNotNull(blobBuilders, "filesystem storage strategy blobBuilders");
|
||||||
this.baseDirectory = checkNotNull(baseDir, "filesystem storage strategy base directory");
|
this.baseDirectory = checkNotNull(baseDir, "filesystem storage strategy base directory");
|
||||||
this.filesystemContainerNameValidator = checkNotNull(filesystemContainerNameValidator, "filesystem container name validator");
|
this.filesystemContainerNameValidator = checkNotNull(filesystemContainerNameValidator,
|
||||||
|
"filesystem container name validator");
|
||||||
this.filesystemBlobKeyValidator = checkNotNull(filesystemBlobKeyValidator, "filesystem blob key validator");
|
this.filesystemBlobKeyValidator = checkNotNull(filesystemBlobKeyValidator, "filesystem blob key validator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,16 +101,15 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
return createDirectoryWithResult(container, null);
|
return createDirectoryWithResult(container, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteContainer(String container) {
|
public void deleteContainer(String container) {
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
deleteDirectory(container, null);
|
deleteDirectory(container, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty the directory of its content (files and subdirectories)
|
* Empty the directory of its content (files and subdirectories)
|
||||||
|
*
|
||||||
* @param container
|
* @param container
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,29 +121,26 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
@Override
|
@Override
|
||||||
public void clearContainer(String container, ListContainerOptions options) {
|
public void clearContainer(String container, ListContainerOptions options) {
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
//TODO
|
// TODO
|
||||||
//now all is deleted, check it based on options
|
// now all is deleted, check it based on options
|
||||||
try {
|
try {
|
||||||
File containerFile = openFolder(container);
|
File containerFile = openFolder(container);
|
||||||
File[] children = containerFile.listFiles();
|
File[] children = containerFile.listFiles();
|
||||||
if (null != children) {
|
if (null != children) {
|
||||||
for(File child:children) {
|
for (File child : children) {
|
||||||
FileUtils.forceDelete(child);
|
FileUtils.forceDelete(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e,"An error occurred while clearing container %s", container);
|
logger.error(e, "An error occurred while clearing container %s", container);
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob newBlob(@ParamValidators( { FilesystemBlobKeyValidator.class }) String name) {
|
public Blob newBlob(@ParamValidators({ FilesystemBlobKeyValidator.class }) String name) {
|
||||||
filesystemBlobKeyValidator.validate(name);
|
filesystemBlobKeyValidator.validate(name);
|
||||||
Blob blob = blobFactory.create(null);
|
return blobBuilders.get().name(name).build();
|
||||||
blob.getMetadata().setName(name);
|
|
||||||
return blob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -153,14 +152,14 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
File fileToBeDeleted = new File(fileName);
|
File fileToBeDeleted = new File(fileName);
|
||||||
fileToBeDeleted.delete();
|
fileToBeDeleted.delete();
|
||||||
|
|
||||||
//now examins if the key of the blob is a complex key (with a directory structure)
|
// now examins if the key of the blob is a complex key (with a directory structure)
|
||||||
//and eventually remove empty directory
|
// and eventually remove empty directory
|
||||||
removeDirectoriesTreeOfBlobKey(container, blobKey);
|
removeDirectoriesTreeOfBlobKey(container, blobKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an iterator that reports all the containers under base path
|
* Return an iterator that reports all the containers under base path
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -168,8 +167,7 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
Iterable<String> containers = new Iterable<String>() {
|
Iterable<String> containers = new Iterable<String>() {
|
||||||
@Override
|
@Override
|
||||||
public Iterator<String> iterator() {
|
public Iterator<String> iterator() {
|
||||||
return new FileIterator(
|
return new FileIterator(buildPathStartingFromBaseDir(), DirectoryFileFilter.INSTANCE);
|
||||||
buildPathStartingFromBaseDir(), DirectoryFileFilter.INSTANCE);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,6 +176,7 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link File} object that links to the blob
|
* Returns a {@link File} object that links to the blob
|
||||||
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* @param blobKey
|
* @param blobKey
|
||||||
* @return
|
* @return
|
||||||
|
@ -191,9 +190,9 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
return blobFile;
|
return blobFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a {@link Blob} {@link Payload} into a file
|
* Write a {@link Blob} {@link Payload} into a file
|
||||||
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* @param blobKey
|
* @param blobKey
|
||||||
* @param payload
|
* @param payload
|
||||||
|
@ -241,9 +240,9 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the blobs key inside a container
|
* Returns all the blobs key inside a container
|
||||||
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -251,8 +250,8 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> getBlobKeysInsideContainer(String container) throws IOException {
|
public Iterable<String> getBlobKeysInsideContainer(String container) throws IOException {
|
||||||
filesystemContainerNameValidator.validate(container);
|
filesystemContainerNameValidator.validate(container);
|
||||||
//check if container exists
|
// check if container exists
|
||||||
//TODO maybe an error is more appropriate
|
// TODO maybe an error is more appropriate
|
||||||
if (!containerExists(container)) {
|
if (!containerExists(container)) {
|
||||||
return new HashSet<String>();
|
return new HashSet<String>();
|
||||||
}
|
}
|
||||||
|
@ -284,7 +283,7 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDirectory(String container, String directory) {
|
public void deleteDirectory(String container, String directory) {
|
||||||
//create complete dir path
|
// create complete dir path
|
||||||
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
||||||
try {
|
try {
|
||||||
FileUtils.forceDelete(new File(fullDirPath));
|
FileUtils.forceDelete(new File(fullDirPath));
|
||||||
|
@ -294,19 +293,15 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long countBlobs(String container, ListContainerOptions options) {
|
public long countBlobs(String container, ListContainerOptions options) {
|
||||||
//TODO
|
// TODO
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------- Private methods
|
||||||
|
|
||||||
|
private boolean buildPathAndChecksIfFileExists(String... tokens) {
|
||||||
|
|
||||||
//---------------------------------------------------------- Private methods
|
|
||||||
|
|
||||||
private boolean buildPathAndChecksIfFileExists(String...tokens) {
|
|
||||||
String path = buildPathStartingFromBaseDir(tokens);
|
String path = buildPathStartingFromBaseDir(tokens);
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
boolean exists = file.exists() || file.isFile();
|
boolean exists = file.exists() || file.isFile();
|
||||||
|
@ -314,32 +309,33 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the file system resource whose name is obtained applying buildPath
|
* Check if the file system resource whose name is obtained applying buildPath on the input path
|
||||||
* on the input path tokens is a directory, otherwise a RuntimeException is thrown
|
* tokens is a directory, otherwise a RuntimeException is thrown
|
||||||
*
|
*
|
||||||
* @param tokens the tokens that make up the name of the resource on the
|
* @param tokens
|
||||||
* file system
|
* the tokens that make up the name of the resource on the file system
|
||||||
*/
|
*/
|
||||||
private boolean buildPathAndChecksIfDirectoryExists(String...tokens) {
|
private boolean buildPathAndChecksIfDirectoryExists(String... tokens) {
|
||||||
String path = buildPathStartingFromBaseDir(tokens);
|
String path = buildPathStartingFromBaseDir(tokens);
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
boolean exists = file.exists() || file.isDirectory();
|
boolean exists = file.exists() || file.isDirectory();
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facility method used to concatenate path tokens normalizing separators
|
* Facility method used to concatenate path tokens normalizing separators
|
||||||
* @param pathTokens all the string in the proper order that must be concatenated
|
*
|
||||||
* in order to obtain the filename
|
* @param pathTokens
|
||||||
|
* all the string in the proper order that must be concatenated in order to obtain the
|
||||||
|
* filename
|
||||||
* @return the resulting string
|
* @return the resulting string
|
||||||
*/
|
*/
|
||||||
protected String buildPathStartingFromBaseDir(String...pathTokens) {
|
protected String buildPathStartingFromBaseDir(String... pathTokens) {
|
||||||
String normalizedToken = removeFileSeparatorFromBorders(normalize(baseDirectory), true);
|
String normalizedToken = removeFileSeparatorFromBorders(normalize(baseDirectory), true);
|
||||||
StringBuilder completePath = new StringBuilder(normalizedToken);
|
StringBuilder completePath = new StringBuilder(normalizedToken);
|
||||||
if(pathTokens!=null && pathTokens.length>0) {
|
if (pathTokens != null && pathTokens.length > 0) {
|
||||||
for(int i=0; i<pathTokens.length; i++) {
|
for (int i = 0; i < pathTokens.length; i++) {
|
||||||
if(pathTokens[i]!=null) {
|
if (pathTokens[i] != null) {
|
||||||
normalizedToken = removeFileSeparatorFromBorders(normalize(pathTokens[i]), false);
|
normalizedToken = removeFileSeparatorFromBorders(normalize(pathTokens[i]), false);
|
||||||
completePath.append(File.separator).append(normalizedToken);
|
completePath.append(File.separator).append(normalizedToken);
|
||||||
}
|
}
|
||||||
|
@ -349,14 +345,15 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Substitutes all the file separator occurrences in the path with a file
|
* Substitutes all the file separator occurrences in the path with a file separator for the
|
||||||
* separator for the current operative system
|
* current operative system
|
||||||
|
*
|
||||||
* @param pathToBeNormalized
|
* @param pathToBeNormalized
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String normalize(String pathToBeNormalized) {
|
private String normalize(String pathToBeNormalized) {
|
||||||
if(null != pathToBeNormalized && pathToBeNormalized.contains(BACK_SLASH)) {
|
if (null != pathToBeNormalized && pathToBeNormalized.contains(BACK_SLASH)) {
|
||||||
if(!BACK_SLASH.equals(File.separator)) {
|
if (!BACK_SLASH.equals(File.separator)) {
|
||||||
return pathToBeNormalized.replaceAll(BACK_SLASH, File.separator);
|
return pathToBeNormalized.replaceAll(BACK_SLASH, File.separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,84 +361,88 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove leading and trailing {@link File.separator} character from the
|
* Remove leading and trailing {@link File.separator} character from the string.
|
||||||
* string.
|
*
|
||||||
* @param pathToBeCleaned
|
* @param pathToBeCleaned
|
||||||
* @param remove only trailing separator char from path
|
* @param remove
|
||||||
|
* only trailing separator char from path
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String removeFileSeparatorFromBorders(String pathToBeCleaned, boolean onlyTrailing) {
|
private String removeFileSeparatorFromBorders(String pathToBeCleaned, boolean onlyTrailing) {
|
||||||
if (null == pathToBeCleaned || pathToBeCleaned.equals("")) return pathToBeCleaned;
|
if (null == pathToBeCleaned || pathToBeCleaned.equals(""))
|
||||||
|
return pathToBeCleaned;
|
||||||
|
|
||||||
int beginIndex = 0;
|
int beginIndex = 0;
|
||||||
int endIndex = pathToBeCleaned.length();
|
int endIndex = pathToBeCleaned.length();
|
||||||
|
|
||||||
//search for separator chars
|
// search for separator chars
|
||||||
if (!onlyTrailing) {
|
if (!onlyTrailing) {
|
||||||
if (pathToBeCleaned.substring(0, 1).equals(File.separator)) beginIndex = 1;
|
if (pathToBeCleaned.substring(0, 1).equals(File.separator))
|
||||||
|
beginIndex = 1;
|
||||||
}
|
}
|
||||||
if (pathToBeCleaned.substring(pathToBeCleaned.length() - 1).equals(File.separator)) endIndex--;
|
if (pathToBeCleaned.substring(pathToBeCleaned.length() - 1).equals(File.separator))
|
||||||
|
endIndex--;
|
||||||
|
|
||||||
return pathToBeCleaned.substring(beginIndex, endIndex);
|
return pathToBeCleaned.substring(beginIndex, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes recursively the directory structure of a complex blob key, only
|
* Removes recursively the directory structure of a complex blob key, only if the directory is
|
||||||
* if the directory is empty
|
* empty
|
||||||
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* @param normalizedKey
|
* @param normalizedKey
|
||||||
*/
|
*/
|
||||||
private void removeDirectoriesTreeOfBlobKey(String container, String blobKey) {
|
private void removeDirectoriesTreeOfBlobKey(String container, String blobKey) {
|
||||||
String normalizedBlobKey = normalize(blobKey);
|
String normalizedBlobKey = normalize(blobKey);
|
||||||
//exists is no path is present in the blobkey
|
// exists is no path is present in the blobkey
|
||||||
if (!normalizedBlobKey.contains(File.separator)) return;
|
if (!normalizedBlobKey.contains(File.separator))
|
||||||
|
return;
|
||||||
|
|
||||||
File file = new File(normalizedBlobKey);
|
File file = new File(normalizedBlobKey);
|
||||||
//TODO
|
// TODO
|
||||||
//"/media/data/works/java/amazon/jclouds/master/filesystem/aa/bb/cc/dd/eef6f0c8-0206-460b-8870-352e6019893c.txt"
|
// "/media/data/works/java/amazon/jclouds/master/filesystem/aa/bb/cc/dd/eef6f0c8-0206-460b-8870-352e6019893c.txt"
|
||||||
String parentPath = file.getParent();
|
String parentPath = file.getParent();
|
||||||
//no need to manage "/" parentPath, because "/" cannot be used as start
|
// no need to manage "/" parentPath, because "/" cannot be used as start
|
||||||
//char of blobkey
|
// char of blobkey
|
||||||
if (null != parentPath || "".equals(parentPath)) {
|
if (null != parentPath || "".equals(parentPath)) {
|
||||||
//remove parent directory only it's empty
|
// remove parent directory only it's empty
|
||||||
File directory = new File(buildPathStartingFromBaseDir(container, parentPath));
|
File directory = new File(buildPathStartingFromBaseDir(container, parentPath));
|
||||||
String[] children = directory.list();
|
String[] children = directory.list();
|
||||||
if (null == children || children.length == 0) {
|
if (null == children || children.length == 0) {
|
||||||
directory.delete();
|
directory.delete();
|
||||||
//recursively call for removing other path
|
// recursively call for removing other path
|
||||||
removeDirectoriesTreeOfBlobKey(container, parentPath);
|
removeDirectoriesTreeOfBlobKey(container, parentPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File openFolder(String folderName) throws IOException {
|
private File openFolder(String folderName) throws IOException {
|
||||||
String baseFolderName = buildPathStartingFromBaseDir(folderName);
|
String baseFolderName = buildPathStartingFromBaseDir(folderName);
|
||||||
File folder = new File(baseFolderName);
|
File folder = new File(baseFolderName);
|
||||||
if(folder.exists()) {
|
if (folder.exists()) {
|
||||||
if(!folder.isDirectory()) {
|
if (!folder.isDirectory()) {
|
||||||
throw new IOException("Resource " + baseFolderName + " isn't a folder.");
|
throw new IOException("Resource " + baseFolderName + " isn't a folder.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FileIterator implements Iterator<String> {
|
||||||
private class FileIterator implements Iterator<String>{
|
|
||||||
int currentFileIndex = 0;
|
int currentFileIndex = 0;
|
||||||
File[] children = new File[0];
|
File[] children = new File[0];
|
||||||
File currentFile = null;
|
File currentFile = null;
|
||||||
|
|
||||||
public FileIterator(String fileName, FileFilter filter) {
|
public FileIterator(String fileName, FileFilter filter) {
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
if(file.exists() && file.isDirectory()) {
|
if (file.exists() && file.isDirectory()) {
|
||||||
children = file.listFiles(filter);
|
children = file.listFiles(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return currentFileIndex<children.length;
|
return currentFileIndex < children.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -452,29 +453,28 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(currentFile!=null && currentFile.exists()) {
|
if (currentFile != null && currentFile.exists()) {
|
||||||
if(!currentFile.delete()) {
|
if (!currentFile.delete()) {
|
||||||
throw new RuntimeException("An error occurred deleting "+currentFile.getName());
|
throw new RuntimeException("An error occurred deleting " + currentFile.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void populateBlobKeysInContainer(File directory, Set<String> blobNames) {
|
private void populateBlobKeysInContainer(File directory, Set<String> blobNames) {
|
||||||
File[] children = directory.listFiles();
|
File[] children = directory.listFiles();
|
||||||
for(File child:children) {
|
for (File child : children) {
|
||||||
if(child.isFile()) {
|
if (child.isFile()) {
|
||||||
blobNames.add(child.getAbsolutePath());
|
blobNames.add(child.getAbsolutePath());
|
||||||
} else if(child.isDirectory()) {
|
} else if (child.isDirectory()) {
|
||||||
populateBlobKeysInContainer(child, blobNames);
|
populateBlobKeysInContainer(child, blobNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a directory and returns the result
|
* Creates a directory and returns the result
|
||||||
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* @param directory
|
* @param directory
|
||||||
* @return true if the directory was created, otherwise false
|
* @return true if the directory was created, otherwise false
|
||||||
|
@ -483,8 +483,8 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
String directoryFullName = buildPathStartingFromBaseDir(container, directory);
|
String directoryFullName = buildPathStartingFromBaseDir(container, directory);
|
||||||
logger.debug("Creating directory %s", directoryFullName);
|
logger.debug("Creating directory %s", directoryFullName);
|
||||||
|
|
||||||
//cannot use directoryFullName, because the following method rebuild
|
// cannot use directoryFullName, because the following method rebuild
|
||||||
//another time the path starting from base directory
|
// another time the path starting from base directory
|
||||||
if (buildPathAndChecksIfDirectoryExists(container, directory)) {
|
if (buildPathAndChecksIfDirectoryExists(container, directory)) {
|
||||||
logger.debug("Directory %s already exists", directoryFullName);
|
logger.debug("Directory %s already exists", directoryFullName);
|
||||||
return false;
|
return false;
|
||||||
|
@ -498,13 +498,15 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
/**
|
/**
|
||||||
* Copy from an InputStream to an OutputStream.
|
* Copy from an InputStream to an OutputStream.
|
||||||
*
|
*
|
||||||
* @param input The InputStream
|
* @param input
|
||||||
* @param output The OutputStream
|
* The InputStream
|
||||||
|
* @param output
|
||||||
|
* The OutputStream
|
||||||
* @return the number of bytes copied
|
* @return the number of bytes copied
|
||||||
* @throws IOException if an error occurs
|
* @throws IOException
|
||||||
|
* if an error occurs
|
||||||
*/
|
*/
|
||||||
private long copy(InputStream input, OutputStream output)
|
private long copy(InputStream input, OutputStream output) throws IOException {
|
||||||
throws IOException {
|
|
||||||
byte[] buffer = new byte[COPY_BUFFER_SIZE];
|
byte[] buffer = new byte[COPY_BUFFER_SIZE];
|
||||||
long count = 0;
|
long count = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -520,5 +522,4 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,18 @@
|
||||||
|
|
||||||
package org.jclouds.filesystem.util.internal;
|
package org.jclouds.filesystem.util.internal;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link BlobUtils} interfaced and act as a bridge to
|
* Implements the {@link BlobUtils} interfaced and act as a bridge to
|
||||||
|
@ -37,18 +41,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
public class FileSystemBlobUtilsImpl implements BlobUtils {
|
||||||
|
|
||||||
protected final FilesystemStorageStrategy storageStrategy;
|
protected final FilesystemStorageStrategy storageStrategy;
|
||||||
|
protected final Provider<BlobBuilder> blobBuilders;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FileSystemBlobUtilsImpl(
|
public FileSystemBlobUtilsImpl(FilesystemStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) {
|
||||||
FilesystemStorageStrategy storageStrategy) {
|
|
||||||
this.storageStrategy = checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
this.storageStrategy = checkNotNull(storageStrategy, "Filesystem Storage Strategy");
|
||||||
|
this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob newBlob(String name) {
|
public Blob newBlob(String name) {
|
||||||
return storageStrategy.newBlob(name);
|
return blobBuilder().name(name).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder blobBuilder() {
|
||||||
|
return blobBuilders.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,7 +57,6 @@ import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.CreationException;
|
import com.google.inject.CreationException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link FilesystemAsyncBlobStore} class
|
* Test class for {@link FilesystemAsyncBlobStore} class
|
||||||
*
|
*
|
||||||
|
@ -68,17 +67,13 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
|
|
||||||
private static final String CONTAINER_NAME = "fun-blobstore-test";
|
private static final String CONTAINER_NAME = "fun-blobstore-test";
|
||||||
private static final String TARGET_CONTAINER_NAME = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME;
|
private static final String TARGET_CONTAINER_NAME = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME;
|
||||||
private static final String LOGGING_CONFIG_KEY
|
private static final String LOGGING_CONFIG_KEY = "java.util.logging.config.file";
|
||||||
= "java.util.logging.config.file";
|
private static final String LOGGING_CONFIG_VALUE = "src/main/resources/logging.properties";
|
||||||
private static final String LOGGING_CONFIG_VALUE
|
|
||||||
= "src/main/resources/logging.properties";
|
|
||||||
|
|
||||||
private static final String PROVIDER = "filesystem";
|
private static final String PROVIDER = "filesystem";
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.setProperty(LOGGING_CONFIG_KEY,
|
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
||||||
LOGGING_CONFIG_VALUE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,56 +83,51 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
//create context for filesystem container
|
// create context for filesystem container
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
|
prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
|
||||||
context = (BlobStoreContext) new BlobStoreContextFactory().createContext(
|
context = (BlobStoreContext) new BlobStoreContextFactory().createContext(PROVIDER, prop);
|
||||||
PROVIDER, prop);
|
// create a container in the default location
|
||||||
//create a container in the default location
|
|
||||||
blobStore = context.getBlobStore();
|
blobStore = context.getBlobStore();
|
||||||
|
|
||||||
resourcesToBeDeleted.add(new File(TestUtils.TARGET_BASE_DIR));
|
resourcesToBeDeleted.add(new File(TestUtils.TARGET_BASE_DIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
protected void tearDown() {
|
protected void tearDown() {
|
||||||
context.close();
|
context.close();
|
||||||
context = null;
|
context = null;
|
||||||
// freeing filesystem resources used for tests
|
// freeing filesystem resources used for tests
|
||||||
Iterator<File> resourceToDelete = resourcesToBeDeleted.iterator();
|
Iterator<File> resourceToDelete = resourcesToBeDeleted.iterator();
|
||||||
while(resourceToDelete.hasNext()) {
|
while (resourceToDelete.hasNext()) {
|
||||||
File fileToDelete = resourceToDelete.next();
|
File fileToDelete = resourceToDelete.next();
|
||||||
try {
|
try {
|
||||||
FileUtils.forceDelete(fileToDelete);
|
FileUtils.forceDelete(fileToDelete);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.err.println("Error deleting folder ["+fileToDelete.getName()+"].");
|
System.err.println("Error deleting folder [" + fileToDelete.getName() + "].");
|
||||||
}
|
}
|
||||||
resourceToDelete.remove();
|
resourceToDelete.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if context parameters are managed in the correct way
|
* Checks if context parameters are managed in the correct way
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void testParameters() {
|
public void testParameters() {
|
||||||
//no base directory declared in properties
|
// no base directory declared in properties
|
||||||
try {
|
try {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
new BlobStoreContextFactory().createContext(
|
new BlobStoreContextFactory().createContext(PROVIDER, props);
|
||||||
PROVIDER, props);
|
|
||||||
fail("No error if base directory is not specified");
|
fail("No error if base directory is not specified");
|
||||||
} catch (CreationException e) {
|
} catch (CreationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//no base directory declared in properties
|
// no base directory declared in properties
|
||||||
try {
|
try {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null);
|
props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null);
|
||||||
new BlobStoreContextFactory().createContext(
|
new BlobStoreContextFactory().createContext(PROVIDER, props);
|
||||||
PROVIDER, props);
|
|
||||||
fail("No error if base directory is null in the option");
|
fail("No error if base directory is null in the option");
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
}
|
}
|
||||||
|
@ -155,9 +145,9 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
|
assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
|
||||||
|
|
||||||
// Testing list with some containers
|
// Testing list with some containers
|
||||||
String[] containerNames = new String[]{"34343", "aaaa", "bbbbb"};
|
String[] containerNames = new String[] { "34343", "aaaa", "bbbbb" };
|
||||||
containersCreated = new HashSet<String>();
|
containersCreated = new HashSet<String>();
|
||||||
for(String containerName:containerNames) {
|
for (String containerName : containerNames) {
|
||||||
blobStore.createContainerInLocation(null, containerName);
|
blobStore.createContainerInLocation(null, containerName);
|
||||||
containersCreated.add(containerName);
|
containersCreated.add(containerName);
|
||||||
}
|
}
|
||||||
|
@ -165,53 +155,45 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
containersRetrieved = blobStore.list();
|
containersRetrieved = blobStore.list();
|
||||||
assertEquals(containersCreated.size(), containersRetrieved.size(), "Different numbers of container");
|
assertEquals(containersCreated.size(), containersRetrieved.size(), "Different numbers of container");
|
||||||
|
|
||||||
for(StorageMetadata data:containersRetrieved) {
|
for (StorageMetadata data : containersRetrieved) {
|
||||||
String containerName = data.getName();
|
String containerName = data.getName();
|
||||||
if(!containersCreated.remove(containerName)) {
|
if (!containersCreated.remove(containerName)) {
|
||||||
fail("Container list contains unexpected value ["+containerName+"]");
|
fail("Container list contains unexpected value [" + containerName + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(containersCreated.isEmpty(), "List operation doesn't return all values.");
|
assertTrue(containersCreated.isEmpty(), "List operation doesn't return all values.");
|
||||||
|
|
||||||
for(String containerName:containerNames) {
|
for (String containerName : containerNames) {
|
||||||
//delete all creaded containers
|
// delete all creaded containers
|
||||||
blobStore.deleteContainer(containerName);
|
blobStore.deleteContainer(containerName);
|
||||||
}
|
}
|
||||||
containersRetrieved = blobStore.list();
|
containersRetrieved = blobStore.list();
|
||||||
assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
|
assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of list method, of class FilesystemAsyncBlobStore.
|
* Test of list method, of class FilesystemAsyncBlobStore.
|
||||||
*/
|
*/
|
||||||
public void testList_NoOptionSingleContainer()
|
public void testList_NoOptionSingleContainer() throws IOException {
|
||||||
throws IOException {
|
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
// Testing list for an empty container
|
// Testing list for an empty container
|
||||||
checkForContainerContent(CONTAINER_NAME, null);
|
checkForContainerContent(CONTAINER_NAME, null);
|
||||||
|
|
||||||
//creates blobs in first container
|
// creates blobs in first container
|
||||||
Set<String> blobsExpected = TestUtils.createBlobsInContainer(
|
Set<String> blobsExpected = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||||
CONTAINER_NAME,
|
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg", "4rrr.jpg",
|
||||||
new String[] {
|
"rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc" + File.separator + "wert.kpg" });
|
||||||
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
|
||||||
"4rrr.jpg",
|
|
||||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
|
||||||
"xdc" + File.separator + "wert.kpg" }
|
|
||||||
);
|
|
||||||
|
|
||||||
checkForContainerContent(CONTAINER_NAME, blobsExpected);
|
checkForContainerContent(CONTAINER_NAME, blobsExpected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testList_NotExistingContainer() {
|
public void testList_NotExistingContainer() {
|
||||||
// Testing list for a not existing container
|
// Testing list for a not existing container
|
||||||
try {
|
try {
|
||||||
blobStore.list(CONTAINER_NAME);
|
blobStore.list(CONTAINER_NAME);
|
||||||
fail("Found a not existing container");
|
fail("Found a not existing container");
|
||||||
} catch(ContainerNotFoundException e) {
|
} catch (ContainerNotFoundException e) {
|
||||||
//ok if arriver here
|
// ok if arriver here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,62 +203,47 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
public void testList_NoOptionDoubleContainer() throws IOException {
|
public void testList_NoOptionDoubleContainer() throws IOException {
|
||||||
final String CONTAINER_NAME2 = "container2";
|
final String CONTAINER_NAME2 = "container2";
|
||||||
|
|
||||||
//create first container
|
// create first container
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
//checks for empty container
|
// checks for empty container
|
||||||
checkForContainerContent(CONTAINER_NAME, null);
|
checkForContainerContent(CONTAINER_NAME, null);
|
||||||
|
|
||||||
//create second container
|
// create second container
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
||||||
//checks for empty
|
// checks for empty
|
||||||
checkForContainerContent(CONTAINER_NAME2, null);
|
checkForContainerContent(CONTAINER_NAME2, null);
|
||||||
|
|
||||||
//creates blobs in first container
|
// creates blobs in first container
|
||||||
|
|
||||||
Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(
|
Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(CONTAINER_NAME,
|
||||||
CONTAINER_NAME,
|
new String[] { "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
||||||
new String[] {
|
TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
||||||
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
"xdc" + File.separator + "wert.kpg" });
|
||||||
TestUtils.createRandomBlobKey(),
|
|
||||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
|
||||||
"xdc" + File.separator + "wert.kpg"}
|
|
||||||
);
|
|
||||||
|
|
||||||
//creates blobs in second container
|
// creates blobs in second container
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
||||||
Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(
|
Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(CONTAINER_NAME2, new String[] {
|
||||||
CONTAINER_NAME2,
|
"asd" + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator
|
||||||
new String[] {
|
+ "1234.jpg", TestUtils.createRandomBlobKey(),
|
||||||
"asd" + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
"rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc" + File.separator + "wert.kpg" });
|
||||||
TestUtils.createRandomBlobKey(),
|
|
||||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
|
||||||
"xdc" + File.separator + "wert.kpg" }
|
|
||||||
);
|
|
||||||
|
|
||||||
//test blobs in first container
|
// test blobs in first container
|
||||||
checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
|
checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
|
||||||
//test blobs in second container
|
// test blobs in second container
|
||||||
checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
|
checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testList_Subdirectory() throws IOException {
|
||||||
public void testList_Subdirectory()
|
|
||||||
throws IOException {
|
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
// Testing list for an empty container
|
// Testing list for an empty container
|
||||||
checkForContainerContent(CONTAINER_NAME, null);
|
checkForContainerContent(CONTAINER_NAME, null);
|
||||||
|
|
||||||
//creates blobs in first container
|
// creates blobs in first container
|
||||||
Set<String> blobsExpected = TestUtils.createBlobsInContainer(
|
Set<String> blobsExpected = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||||
CONTAINER_NAME,
|
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg", "4rrr.jpg",
|
||||||
new String[] {
|
"rrr" + File.separator + "sss" + File.separator + "788.jpg", "rrr" + File.separator + "wert.kpg" });
|
||||||
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
|
||||||
"4rrr.jpg",
|
|
||||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
|
||||||
"rrr" + File.separator + "wert.kpg" }
|
|
||||||
);
|
|
||||||
|
|
||||||
//remove not expected values
|
// remove not expected values
|
||||||
blobsExpected.remove("bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg");
|
blobsExpected.remove("bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg");
|
||||||
blobsExpected.remove("4rrr.jpg");
|
blobsExpected.remove("4rrr.jpg");
|
||||||
|
|
||||||
|
@ -284,63 +251,52 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO Should throws an exception?
|
||||||
* Should throws an exception?
|
|
||||||
*/
|
*/
|
||||||
public void testClearContainer_NotExistingContainer(){
|
public void testClearContainer_NotExistingContainer() {
|
||||||
blobStore.clearContainer(CONTAINER_NAME);
|
blobStore.clearContainer(CONTAINER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test, because clearContainer is not redefined in
|
* Integration test, because clearContainer is not redefined in {@link FilesystemAsyncBlobStore}
|
||||||
* {@link FilesystemAsyncBlobStore} class
|
* class
|
||||||
*/
|
*/
|
||||||
public void testClearContainer_NoOptions() throws IOException {
|
public void testClearContainer_NoOptions() throws IOException {
|
||||||
final String CONTAINER_NAME2 = "containerToClear";
|
final String CONTAINER_NAME2 = "containerToClear";
|
||||||
|
|
||||||
//create containers
|
// create containers
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
||||||
|
|
||||||
//creates blobs in first container
|
// creates blobs in first container
|
||||||
Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(
|
Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(CONTAINER_NAME,
|
||||||
CONTAINER_NAME,
|
new String[] { "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
||||||
new String[] {
|
TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
||||||
"bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
"xdc" + File.separator + "wert.kpg" });
|
||||||
TestUtils.createRandomBlobKey(),
|
|
||||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
|
||||||
"xdc" + File.separator + "wert.kpg"}
|
|
||||||
);
|
|
||||||
|
|
||||||
//creates blobs in second container
|
// creates blobs in second container
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME2);
|
||||||
Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(
|
Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(CONTAINER_NAME2, new String[] {
|
||||||
CONTAINER_NAME2,
|
"asd" + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator
|
||||||
new String[] {
|
+ "1234.jpg", TestUtils.createRandomBlobKey(),
|
||||||
"asd" + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
|
"rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc" + File.separator + "wert.kpg" });
|
||||||
TestUtils.createRandomBlobKey(),
|
|
||||||
"rrr" + File.separator + "sss" + File.separator + "788.jpg",
|
|
||||||
"xdc" + File.separator + "wert.kpg" }
|
|
||||||
);
|
|
||||||
|
|
||||||
//test blobs in containers
|
// test blobs in containers
|
||||||
checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
|
checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
|
||||||
checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
|
checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
|
||||||
|
|
||||||
//delete blobs in first container
|
// delete blobs in first container
|
||||||
blobStore.clearContainer(CONTAINER_NAME);
|
blobStore.clearContainer(CONTAINER_NAME);
|
||||||
checkForContainerContent(CONTAINER_NAME, null);
|
checkForContainerContent(CONTAINER_NAME, null);
|
||||||
checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
|
checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
|
||||||
//delete blobs in second container
|
// delete blobs in second container
|
||||||
blobStore.clearContainer(CONTAINER_NAME2);
|
blobStore.clearContainer(CONTAINER_NAME2);
|
||||||
checkForContainerContent(CONTAINER_NAME2, null);
|
checkForContainerContent(CONTAINER_NAME2, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test, because countBlobs is not redefined in
|
* Integration test, because countBlobs is not redefined in {@link FilesystemAsyncBlobStore}
|
||||||
* {@link FilesystemAsyncBlobStore} class
|
* class
|
||||||
*/
|
*/
|
||||||
public void testCountBlobs_NotExistingContainer() {
|
public void testCountBlobs_NotExistingContainer() {
|
||||||
try {
|
try {
|
||||||
|
@ -351,8 +307,8 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test, because countBlobs is not redefined in
|
* Integration test, because countBlobs is not redefined in {@link FilesystemAsyncBlobStore}
|
||||||
* {@link FilesystemAsyncBlobStore} class
|
* class
|
||||||
*/
|
*/
|
||||||
public void testCountBlobs_NoOptionsEmptyContainer() {
|
public void testCountBlobs_NoOptionsEmptyContainer() {
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
@ -364,8 +320,8 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test, because countBlobs is not redefined in
|
* Integration test, because countBlobs is not redefined in {@link FilesystemAsyncBlobStore}
|
||||||
* {@link FilesystemAsyncBlobStore} class
|
* class
|
||||||
*/
|
*/
|
||||||
public void testCountBlobs_NoOptions() {
|
public void testCountBlobs_NoOptions() {
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
@ -376,56 +332,48 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testRemoveBlob_SimpleBlobKey() throws IOException {
|
public void testRemoveBlob_SimpleBlobKey() throws IOException {
|
||||||
final String BLOB_KEY = TestUtils.createRandomBlobKey(null, ".txt");
|
final String BLOB_KEY = TestUtils.createRandomBlobKey(null, ".txt");
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
|
||||||
//checks that blob doesn't exists
|
// checks that blob doesn't exists
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertFalse(result, "Blob exists");
|
assertFalse(result, "Blob exists");
|
||||||
|
|
||||||
//create the blob
|
// create the blob
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { BLOB_KEY });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[] { BLOB_KEY }
|
|
||||||
);
|
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertTrue(result, "Blob exists");
|
assertTrue(result, "Blob exists");
|
||||||
|
|
||||||
//remove it
|
// remove it
|
||||||
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
|
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertFalse(result, "Blob still exists");
|
assertFalse(result, "Blob still exists");
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testRemoveBlob_TwoSimpleBlobKeys() throws IOException {
|
public void testRemoveBlob_TwoSimpleBlobKeys() throws IOException {
|
||||||
final String BLOB_KEY1 = TestUtils.createRandomBlobKey(null, null);
|
final String BLOB_KEY1 = TestUtils.createRandomBlobKey(null, null);
|
||||||
final String BLOB_KEY2 = TestUtils.createRandomBlobKey(null, null);
|
final String BLOB_KEY2 = TestUtils.createRandomBlobKey(null, null);
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
//create the container and checks that blob doesn't exists
|
// create the container and checks that blob doesn't exists
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
||||||
assertFalse(result, "Blob1 exists");
|
assertFalse(result, "Blob1 exists");
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
||||||
assertFalse(result, "Blob2 exists");
|
assertFalse(result, "Blob2 exists");
|
||||||
|
|
||||||
//create the blob
|
// create the blob
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { BLOB_KEY1, BLOB_KEY2 });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[] { BLOB_KEY1, BLOB_KEY2 }
|
|
||||||
);
|
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
||||||
assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
|
assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
||||||
assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
|
assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
|
||||||
|
|
||||||
//remove first blob
|
// remove first blob
|
||||||
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
|
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
||||||
assertFalse(result, "Blob1 still exists");
|
assertFalse(result, "Blob1 still exists");
|
||||||
|
@ -433,14 +381,13 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertTrue(result, "Blob2 doesn't exist");
|
assertTrue(result, "Blob2 doesn't exist");
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
|
||||||
//remove second blob
|
// remove second blob
|
||||||
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
|
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
||||||
assertFalse(result, "Blob2 still exists");
|
assertFalse(result, "Blob2 still exists");
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of removeBlob method, with only one blob with a complex path as key
|
* Test of removeBlob method, with only one blob with a complex path as key
|
||||||
*/
|
*/
|
||||||
|
@ -448,35 +395,30 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
|
final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
//checks that blob doesn't exists
|
// checks that blob doesn't exists
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertFalse(result, "Blob exists");
|
assertFalse(result, "Blob exists");
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
|
||||||
|
|
||||||
//create the blob
|
// create the blob
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { BLOB_KEY });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[] { BLOB_KEY }
|
|
||||||
);
|
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertTrue(result, "Blob doesn't exist");
|
assertTrue(result, "Blob doesn't exist");
|
||||||
|
|
||||||
//remove it
|
// remove it
|
||||||
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
|
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertFalse(result, "Blob still exists");
|
assertFalse(result, "Blob still exists");
|
||||||
//file removed
|
// file removed
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
|
||||||
//also the entire directory structure was removed
|
// also the entire directory structure was removed
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of removeBlob method, with two blobs with a complex path as key and
|
* Test of removeBlob method, with two blobs with a complex path as key and when first blob is
|
||||||
* when first blob is removed, not all of its key's path is removed, because
|
* removed, not all of its key's path is removed, because it is shared with the second blob's key
|
||||||
* it is shared with the second blob's key
|
|
||||||
*/
|
*/
|
||||||
public void testRemoveBlob_TwoComplexBlobKeys() throws IOException {
|
public void testRemoveBlob_TwoComplexBlobKeys() throws IOException {
|
||||||
final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
|
final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
|
||||||
|
@ -485,43 +427,39 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
|
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
|
||||||
//checks that blob doesn't exist
|
// checks that blob doesn't exist
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
||||||
assertFalse(result, "Blob1 exists");
|
assertFalse(result, "Blob1 exists");
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
||||||
assertFalse(result, "Blob2 exists");
|
assertFalse(result, "Blob2 exists");
|
||||||
|
|
||||||
//create the blobs
|
// create the blobs
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { BLOB_KEY1, BLOB_KEY2 });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[] { BLOB_KEY1, BLOB_KEY2 }
|
|
||||||
);
|
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
||||||
assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
|
assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
||||||
assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
|
assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
|
||||||
|
|
||||||
//remove first blob
|
// remove first blob
|
||||||
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
|
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
|
||||||
assertFalse(result, "Blob still exists");
|
assertFalse(result, "Blob still exists");
|
||||||
//first file deleted, not the second
|
// first file deleted, not the second
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
|
||||||
//only partial directory structure was removed, because it shares a path
|
// only partial directory structure was removed, because it shares a path
|
||||||
//with the second blob created
|
// with the second blob created
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb/cc/dd", false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb/cc/dd", false);
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb", true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb", true);
|
||||||
//remove second blob
|
// remove second blob
|
||||||
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
|
blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
|
||||||
assertFalse(result, "Blob still exists");
|
assertFalse(result, "Blob still exists");
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
|
||||||
//now all the directory structure is empty
|
// now all the directory structure is empty
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of containerExists method, of class FilesystemAsyncBlobStore.
|
* Test of containerExists method, of class FilesystemAsyncBlobStore.
|
||||||
*/
|
*/
|
||||||
|
@ -531,14 +469,13 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
result = blobStore.containerExists(CONTAINER_NAME);
|
result = blobStore.containerExists(CONTAINER_NAME);
|
||||||
assertFalse(result, "Container exists");
|
assertFalse(result, "Container exists");
|
||||||
|
|
||||||
//create container
|
// create container
|
||||||
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
||||||
|
|
||||||
result = blobStore.containerExists(CONTAINER_NAME);
|
result = blobStore.containerExists(CONTAINER_NAME);
|
||||||
assertTrue(result, "Container doesn't exist");
|
assertTrue(result, "Container doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of createContainerInLocation method, of class FilesystemAsyncBlobStore.
|
* Test of createContainerInLocation method, of class FilesystemAsyncBlobStore.
|
||||||
*/
|
*/
|
||||||
|
@ -564,15 +501,13 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertTrue(result, "Container doesn't exist");
|
assertTrue(result, "Container doesn't exist");
|
||||||
TestUtils.directoryExists(TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2, true);
|
TestUtils.directoryExists(TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2, true);
|
||||||
|
|
||||||
//clean the environment
|
// clean the environment
|
||||||
FileUtils.forceDelete(new File(TARGET_CONTAINER_NAME2));
|
FileUtils.forceDelete(new File(TARGET_CONTAINER_NAME2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of putBlob method, of class FilesystemAsyncBlobStore.
|
* Test of putBlob method, of class FilesystemAsyncBlobStore. with a simple filename - no path in
|
||||||
* with a simple filename - no path in the filename, eg
|
* the filename, eg filename.jpg
|
||||||
* filename.jpg
|
|
||||||
*/
|
*/
|
||||||
public void testPutBlobSimpleName() {
|
public void testPutBlobSimpleName() {
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
@ -581,8 +516,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of putBlob method with a complex key, with path in the filename, eg
|
* Test of putBlob method with a complex key, with path in the filename, eg picture/filename.jpg
|
||||||
* picture/filename.jpg
|
|
||||||
*/
|
*/
|
||||||
public void testPutBlobComplexName1() {
|
public void testPutBlobComplexName1() {
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
@ -593,8 +527,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of putBlob method with a complex key, with path in the filename, eg
|
* Test of putBlob method with a complex key, with path in the filename, eg picture/filename.jpg
|
||||||
* picture/filename.jpg
|
|
||||||
*/
|
*/
|
||||||
public void testPutBlobComplexName2() {
|
public void testPutBlobComplexName2() {
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
@ -603,7 +536,6 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
|
putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of blobExists method, of class FilesystemAsyncBlobStore.
|
* Test of blobExists method, of class FilesystemAsyncBlobStore.
|
||||||
*/
|
*/
|
||||||
|
@ -611,22 +543,22 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
boolean result;
|
boolean result;
|
||||||
String blobKey;
|
String blobKey;
|
||||||
|
|
||||||
//when location doesn't exists
|
// when location doesn't exists
|
||||||
blobKey = TestUtils.createRandomBlobKey();
|
blobKey = TestUtils.createRandomBlobKey();
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
||||||
assertFalse(result, "Blob exists");
|
assertFalse(result, "Blob exists");
|
||||||
|
|
||||||
//when location exists
|
// when location exists
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
||||||
assertFalse(result, "Blob exists");
|
assertFalse(result, "Blob exists");
|
||||||
|
|
||||||
//create blob
|
// create blob
|
||||||
TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload());
|
TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload());
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
||||||
assertTrue(result, "Blob doesn't exist");
|
assertTrue(result, "Blob doesn't exist");
|
||||||
|
|
||||||
//complex path test
|
// complex path test
|
||||||
blobKey = TestUtils.createRandomBlobKey("ss/asdas/", "");
|
blobKey = TestUtils.createRandomBlobKey("ss/asdas/", "");
|
||||||
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
result = blobStore.blobExists(CONTAINER_NAME, blobKey);
|
||||||
assertFalse(result, "Blob exists");
|
assertFalse(result, "Blob exists");
|
||||||
|
@ -635,13 +567,12 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertTrue(result, "Blob doesn't exist");
|
assertTrue(result, "Blob doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGetBlob_NotExistingContainer() {
|
public void testGetBlob_NotExistingContainer() {
|
||||||
try {
|
try {
|
||||||
blobStore.getBlob(CONTAINER_NAME, TestUtils.createRandomBlobKey(), null);
|
blobStore.getBlob(CONTAINER_NAME, TestUtils.createRandomBlobKey(), null);
|
||||||
fail("Retrieve must fail, container does not exist.");
|
fail("Retrieve must fail, container does not exist.");
|
||||||
} catch(ContainerNotFoundException e) {
|
} catch (ContainerNotFoundException e) {
|
||||||
//correct if arrive here
|
// correct if arrive here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,33 +589,27 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
|
resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
|
||||||
assertNull(resultBlob, "Blob exists");
|
assertNull(resultBlob, "Blob exists");
|
||||||
|
|
||||||
//create blob
|
// create blob
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { blobKey });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[]{blobKey});
|
|
||||||
|
|
||||||
resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
|
resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
|
||||||
|
|
||||||
assertNotNull(resultBlob, "Blob exists");
|
assertNotNull(resultBlob, "Blob exists");
|
||||||
//checks file content
|
// checks file content
|
||||||
InputStream expectedFile = new FileInputStream(TARGET_CONTAINER_NAME + File.separator + blobKey);
|
InputStream expectedFile = new FileInputStream(TARGET_CONTAINER_NAME + File.separator + blobKey);
|
||||||
InputStream currentFile = resultBlob.getPayload().getInput();
|
InputStream currentFile = resultBlob.getPayload().getInput();
|
||||||
assertTrue(TestUtils.isSame(expectedFile, currentFile), "Blob payload differs from file content");
|
assertTrue(TestUtils.isSame(expectedFile, currentFile), "Blob payload differs from file content");
|
||||||
//metadata are verified in the test for blobMetadata, so no need to
|
// metadata are verified in the test for blobMetadata, so no need to
|
||||||
//perform a complete test here
|
// perform a complete test here
|
||||||
assertNotNull(resultBlob.getMetadata(), "Metadata null");
|
assertNotNull(resultBlob.getMetadata(), "Metadata null");
|
||||||
MutableBlobMetadata metadata = resultBlob.getMetadata();
|
MutableBlobMetadata metadata = resultBlob.getMetadata();
|
||||||
assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
|
assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBlobMetadata_withDefaultMetadata() throws IOException {
|
public void testBlobMetadata_withDefaultMetadata() throws IOException {
|
||||||
String BLOB_KEY = TestUtils.createRandomBlobKey(null, null);
|
String BLOB_KEY = TestUtils.createRandomBlobKey(null, null);
|
||||||
//create the blob
|
// create the blob
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { BLOB_KEY });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[]{ BLOB_KEY }
|
|
||||||
);
|
|
||||||
|
|
||||||
BlobMetadata metadata = blobStore.blobMetadata(CONTAINER_NAME, BLOB_KEY);
|
BlobMetadata metadata = blobStore.blobMetadata(CONTAINER_NAME, BLOB_KEY);
|
||||||
assertNotNull(metadata, "Metadata null");
|
assertNotNull(metadata, "Metadata null");
|
||||||
|
@ -698,15 +623,14 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertEquals(metadata.getUri(), null, "Wrong blob URI");
|
assertEquals(metadata.getUri(), null, "Wrong blob URI");
|
||||||
assertNotNull(metadata.getUserMetadata(), "No blob UserMetadata");
|
assertNotNull(metadata.getUserMetadata(), "No blob UserMetadata");
|
||||||
assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
|
assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
|
||||||
//metadata.getLastModified()
|
// metadata.getLastModified()
|
||||||
File file = new File(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY);
|
File file = new File(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY);
|
||||||
assertEquals(metadata.getContentMetadata().getContentLength(), new Long(file.length()), "Wrong blob size");
|
assertEquals(metadata.getContentMetadata().getContentLength(), new Long(file.length()), "Wrong blob size");
|
||||||
//don't know how to calculate ETAG
|
// don't know how to calculate ETAG
|
||||||
//assertEquals(metadata.getETag(), "105cf4e6c052d65352dabd20028ff102", "Wrong blob ETag");
|
// assertEquals(metadata.getETag(), "105cf4e6c052d65352dabd20028ff102", "Wrong blob ETag");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDeleteContainer_NotExistingContainer() {
|
||||||
public void testDeleteContainer_NotExistingContainer(){
|
|
||||||
try {
|
try {
|
||||||
blobStore.deleteContainer(CONTAINER_NAME);
|
blobStore.deleteContainer(CONTAINER_NAME);
|
||||||
fail("No error when container doesn't exist");
|
fail("No error when container doesn't exist");
|
||||||
|
@ -714,7 +638,7 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteContainer_EmptyContanier(){
|
public void testDeleteContainer_EmptyContanier() {
|
||||||
boolean result;
|
boolean result;
|
||||||
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
blobStore.createContainerInLocation(null, CONTAINER_NAME);
|
||||||
|
|
||||||
|
@ -722,15 +646,14 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertTrue(result, "Container doesn't exists");
|
assertTrue(result, "Container doesn't exists");
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
||||||
|
|
||||||
//delete container
|
// delete container
|
||||||
blobStore.deleteContainer(CONTAINER_NAME);
|
blobStore.deleteContainer(CONTAINER_NAME);
|
||||||
result = blobStore.containerExists(CONTAINER_NAME);
|
result = blobStore.containerExists(CONTAINER_NAME);
|
||||||
assertFalse(result, "Container still exists");
|
assertFalse(result, "Container still exists");
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDeleteContainer() throws IOException {
|
||||||
public void testDeleteContainer() throws IOException{
|
|
||||||
boolean result;
|
boolean result;
|
||||||
String CONTAINER_NAME2 = "container-to-delete";
|
String CONTAINER_NAME2 = "container-to-delete";
|
||||||
String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
|
String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
|
||||||
|
@ -744,24 +667,18 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
assertTrue(result, "Container [" + CONTAINER_NAME2 + "] doesn't exists");
|
assertTrue(result, "Container [" + CONTAINER_NAME2 + "] doesn't exists");
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
|
||||||
|
|
||||||
//create blobs inside container
|
// create blobs inside container
|
||||||
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
|
||||||
|
TestUtils.createRandomBlobKey("testutils-", null), TestUtils.createRandomBlobKey("testutils-", null),
|
||||||
|
TestUtils.createRandomBlobKey("ab123s" + File.separator + "testutils-", null), });
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("testutils-", null),
|
||||||
TestUtils.createRandomBlobKey("testutils-", null),
|
|
||||||
TestUtils.createRandomBlobKey("testutils-", null),
|
|
||||||
TestUtils.createRandomBlobKey("ab123s" + File.separator + "testutils-", null),
|
|
||||||
});
|
|
||||||
TestUtils.createBlobsInContainer(
|
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[]{
|
|
||||||
TestUtils.createRandomBlobKey("testutils-", null),
|
|
||||||
TestUtils.createRandomBlobKey("testutils-", null),
|
TestUtils.createRandomBlobKey("testutils-", null),
|
||||||
TestUtils.createRandomBlobKey("asda123s" + File.separator + "testutils-", null),
|
TestUtils.createRandomBlobKey("asda123s" + File.separator + "testutils-", null),
|
||||||
TestUtils.createRandomBlobKey("123-_3s" + File.separator + "testutils-", null),
|
TestUtils.createRandomBlobKey("123-_3s" + File.separator + "testutils-", null), });
|
||||||
});
|
|
||||||
|
|
||||||
//delete first container
|
// delete first container
|
||||||
blobStore.deleteContainer(CONTAINER_NAME);
|
blobStore.deleteContainer(CONTAINER_NAME);
|
||||||
result = blobStore.containerExists(CONTAINER_NAME);
|
result = blobStore.containerExists(CONTAINER_NAME);
|
||||||
assertFalse(result, "Container [" + CONTAINER_NAME + "] still exists");
|
assertFalse(result, "Container [" + CONTAINER_NAME + "] still exists");
|
||||||
|
@ -769,57 +686,54 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
result = blobStore.containerExists(CONTAINER_NAME2);
|
result = blobStore.containerExists(CONTAINER_NAME2);
|
||||||
assertTrue(result, "Container [" + CONTAINER_NAME2 + "] still exists");
|
assertTrue(result, "Container [" + CONTAINER_NAME2 + "] still exists");
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
|
||||||
//delete second container
|
// delete second container
|
||||||
blobStore.deleteContainer(CONTAINER_NAME2);
|
blobStore.deleteContainer(CONTAINER_NAME2);
|
||||||
result = blobStore.containerExists(CONTAINER_NAME2);
|
result = blobStore.containerExists(CONTAINER_NAME2);
|
||||||
assertFalse(result, "Container [" + CONTAINER_NAME2 + "] still exists");
|
assertFalse(result, "Container [" + CONTAINER_NAME2 + "] still exists");
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testInvalidContainerName() {
|
public void testInvalidContainerName() {
|
||||||
try {
|
try {
|
||||||
blobStore.createContainerInLocation(null, "file/system");
|
blobStore.createContainerInLocation(null, "file/system");
|
||||||
fail("Wrong container name not recognized");
|
fail("Wrong container name not recognized");
|
||||||
} catch (IllegalArgumentException e) {}
|
} catch (IllegalArgumentException e) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
blobStore.containerExists("file/system");
|
blobStore.containerExists("file/system");
|
||||||
fail("Wrong container name not recognized");
|
fail("Wrong container name not recognized");
|
||||||
} catch (IllegalArgumentException e) {}
|
} catch (IllegalArgumentException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testInvalidBlobKey() {
|
// public void testInvalidBlobKey() {
|
||||||
// try {
|
// try {
|
||||||
// blobStore.newBlob(File.separator + "testwrongblobkey");
|
// blobStore.newBlob(File.separator + "testwrongblobkey");
|
||||||
// fail("Wrong blob key not recognized");
|
// fail("Wrong blob key not recognized");
|
||||||
// } catch (IllegalArgumentException e) {}
|
// } catch (IllegalArgumentException e) {}
|
||||||
//
|
//
|
||||||
// try {
|
// try {
|
||||||
// blobStore.newBlob("testwrongblobkey" + File.separator);
|
// blobStore.newBlob("testwrongblobkey" + File.separator);
|
||||||
// fail("Wrong blob key not recognized");
|
// fail("Wrong blob key not recognized");
|
||||||
// } catch (IllegalArgumentException e) {}
|
// } catch (IllegalArgumentException e) {}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// ---------------------------------------------------------- Private Methods
|
||||||
|
|
||||||
//---------------------------------------------------------- Private Methods
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Blob} object filled with data from a file
|
* Creates a {@link Blob} object filled with data from a file
|
||||||
|
*
|
||||||
* @param keyName
|
* @param keyName
|
||||||
* @param fileContent
|
* @param fileContent
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Blob createBlob(String keyName, File filePayload) {
|
private Blob createBlob(String keyName, File filePayload) {
|
||||||
Blob blob = blobStore.newBlob(keyName);
|
return blobStore.blobBuilder(keyName).payload(filePayload).build();
|
||||||
blob.setPayload(filePayload);
|
|
||||||
return blob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if container contains only the expected blobs
|
* Tests if container contains only the expected blobs
|
||||||
|
*
|
||||||
* @param containerName
|
* @param containerName
|
||||||
* @param expectedBlobKeys
|
* @param expectedBlobKeys
|
||||||
*/
|
*/
|
||||||
|
@ -829,29 +743,32 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
|
|
||||||
private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
|
private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
|
||||||
ListContainerOptions options = ListContainerOptions.Builder.recursive();
|
ListContainerOptions options = ListContainerOptions.Builder.recursive();
|
||||||
if (null != inDirectory && !"".equals(inDirectory)) options.inDirectory(inDirectory);
|
if (null != inDirectory && !"".equals(inDirectory))
|
||||||
|
options.inDirectory(inDirectory);
|
||||||
|
|
||||||
PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
|
PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
|
||||||
|
|
||||||
//nothing expected
|
// nothing expected
|
||||||
if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) {
|
if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) {
|
||||||
assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the containter [" + containerName + "]");
|
assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the containter [" + containerName + "]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//copies values
|
// copies values
|
||||||
Set<String> expectedBlobKeysCopy = new HashSet<String>();
|
Set<String> expectedBlobKeysCopy = new HashSet<String>();
|
||||||
for (String value:expectedBlobKeys){
|
for (String value : expectedBlobKeys) {
|
||||||
expectedBlobKeysCopy.add(value);
|
expectedBlobKeysCopy.add(value);
|
||||||
}
|
}
|
||||||
assertEquals(blobsRetrieved.size(), expectedBlobKeysCopy.size(), "Wrong blob number retrieved in the containter [" + containerName + "]");
|
assertEquals(blobsRetrieved.size(), expectedBlobKeysCopy.size(),
|
||||||
|
"Wrong blob number retrieved in the containter [" + containerName + "]");
|
||||||
for (StorageMetadata data : blobsRetrieved) {
|
for (StorageMetadata data : blobsRetrieved) {
|
||||||
String blobName = data.getName();
|
String blobName = data.getName();
|
||||||
if (!expectedBlobKeysCopy.remove(blobName)) {
|
if (!expectedBlobKeysCopy.remove(blobName)) {
|
||||||
fail("List for container [" + containerName + "] contains unexpected value [" + blobName + "]");
|
fail("List for container [" + containerName + "] contains unexpected value [" + blobName + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(expectedBlobKeysCopy.isEmpty(), "List operation for container [" + containerName + "] doesn't return all values.");
|
assertTrue(expectedBlobKeysCopy.isEmpty(), "List operation for container [" + containerName
|
||||||
|
+ "] doesn't return all values.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -862,13 +779,13 @@ public class FilesystemAsyncBlobStoreTest {
|
||||||
|
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false);
|
||||||
|
|
||||||
//create the blob
|
// create the blob
|
||||||
blob = createBlob(blobKey, TestUtils.getImageForBlobPayload());
|
blob = createBlob(blobKey, TestUtils.getImageForBlobPayload());
|
||||||
String eTag = blobStore.putBlob(CONTAINER_NAME, blob);
|
String eTag = blobStore.putBlob(CONTAINER_NAME, blob);
|
||||||
assertNotNull(eTag, "putBlob result null");
|
assertNotNull(eTag, "putBlob result null");
|
||||||
assertNotSame(eTag, "", "putBlob result empty");
|
assertNotSame(eTag, "", "putBlob result empty");
|
||||||
|
|
||||||
//checks if the blob exists
|
// checks if the blob exists
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, true);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,19 +46,16 @@ public class FilesystemContainerIntegrationTest extends BaseContainerIntegration
|
||||||
|
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
|
|
||||||
Blob object = context.getBlobStore().newBlob(key);
|
|
||||||
object.setPayload(TEST_STRING);
|
|
||||||
object.getMetadata().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
|
||||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the
|
// NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the
|
||||||
// providers.
|
// providers.
|
||||||
object.getMetadata().getUserMetadata().put("Adrian", "powderpuff");
|
Blob object = context.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||||
|
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).build();
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addBlobToContainer(containerName, object);
|
addBlobToContainer(containerName, object);
|
||||||
validateContent(containerName, key);
|
validateContent(containerName, key);
|
||||||
|
|
||||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName,
|
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, maxResults(1));
|
||||||
maxResults(1));
|
|
||||||
|
|
||||||
BlobMetadata metadata = (BlobMetadata) Iterables.getOnlyElement(container);
|
BlobMetadata metadata = (BlobMetadata) Iterables.getOnlyElement(container);
|
||||||
// transient container should be lenient and not return metadata on undetailed listing.
|
// transient container should be lenient and not return metadata on undetailed listing.
|
||||||
|
|
|
@ -19,12 +19,12 @@
|
||||||
|
|
||||||
package org.jclouds.filesystem.strategy.internal;
|
package org.jclouds.filesystem.strategy.internal;
|
||||||
|
|
||||||
import java.util.List;
|
import static org.testng.Assert.assertEquals;
|
||||||
import java.util.Set;
|
import static org.testng.Assert.assertFalse;
|
||||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import org.jclouds.blobstore.domain.internal.BlobImpl;
|
import static org.testng.Assert.assertTrue;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import static org.testng.Assert.fail;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -32,15 +32,23 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
|
import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
|
||||||
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
|
||||||
|
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||||
import org.jclouds.filesystem.utils.TestUtils;
|
import org.jclouds.filesystem.utils.TestUtils;
|
||||||
import org.jclouds.io.payloads.FilePayload;
|
import org.jclouds.io.payloads.FilePayload;
|
||||||
import org.testng.annotations.*;
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
import static org.testng.Assert.*;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link FilesystemStorageStrategyImpl } class
|
* Test class for {@link FilesystemStorageStrategyImpl } class
|
||||||
|
@ -58,34 +66,28 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
private static final String FS = File.separator;
|
private static final String FS = File.separator;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.setProperty(LOGGING_CONFIG_KEY,
|
System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
|
||||||
LOGGING_CONFIG_VALUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FilesystemStorageStrategy storageStrategy;
|
private FilesystemStorageStrategy storageStrategy;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
storageStrategy = new FilesystemStorageStrategyImpl(
|
storageStrategy = new FilesystemStorageStrategyImpl(new Provider<BlobBuilder>() {
|
||||||
new Blob.Factory() {
|
|
||||||
@Override
|
@Override
|
||||||
public Blob create(MutableBlobMetadata metadata) {
|
public BlobBuilder get() {
|
||||||
return new BlobImpl(metadata != null ? metadata : new MutableBlobMetadataImpl());
|
return new BlobBuilderImpl();
|
||||||
}
|
|
||||||
},
|
|
||||||
TestUtils.TARGET_BASE_DIR,
|
|
||||||
new FilesystemContainerNameValidatorImpl(),
|
|
||||||
new FilesystemBlobKeyValidatorImpl());
|
|
||||||
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}, TestUtils.TARGET_BASE_DIR, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
||||||
|
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
protected void tearDown() throws IOException {
|
protected void tearDown() throws IOException {
|
||||||
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
|
TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCreateDirectory() {
|
public void testCreateDirectory() {
|
||||||
storageStrategy.createDirectory(CONTAINER_NAME, null);
|
storageStrategy.createDirectory(CONTAINER_NAME, null);
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
||||||
|
@ -112,11 +114,10 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
try {
|
try {
|
||||||
storageStrategy.createDirectory(CONTAINER_NAME, "$%&!'`\\/");
|
storageStrategy.createDirectory(CONTAINER_NAME, "$%&!'`\\/");
|
||||||
fail("No exception throwed");
|
fail("No exception throwed");
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCreateContainer() {
|
public void testCreateContainer() {
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
|
@ -136,18 +137,14 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertFalse(result, "Container not created");
|
assertFalse(result, "Container not created");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testDeleteDirectory() throws IOException {
|
public void testDeleteDirectory() throws IOException {
|
||||||
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
||||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
|
||||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg")
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//delete directory in different ways
|
// delete directory in different ways
|
||||||
storageStrategy.deleteDirectory(CONTAINER_NAME, "lev1" + FS + "lev2" + FS + "lev4");
|
storageStrategy.deleteDirectory(CONTAINER_NAME, "lev1" + FS + "lev2" + FS + "lev4");
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2" + FS + "lev4", false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2" + FS + "lev4", false);
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2", true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1" + FS + "lev2", true);
|
||||||
|
@ -160,27 +157,23 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1", false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "lev1", false);
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
||||||
|
|
||||||
//delete the directory and all the files inside
|
// delete the directory and all the files inside
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
||||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
|
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
|
||||||
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg")
|
|
||||||
}
|
|
||||||
);
|
|
||||||
storageStrategy.deleteDirectory(CONTAINER_NAME, null);
|
storageStrategy.deleteDirectory(CONTAINER_NAME, null);
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteDirectory_ErrorWhenNotExists(){
|
public void testDeleteDirectory_ErrorWhenNotExists() {
|
||||||
try {
|
try {
|
||||||
storageStrategy.deleteDirectory(CONTAINER_NAME, null);
|
storageStrategy.deleteDirectory(CONTAINER_NAME, null);
|
||||||
fail("No exception throwed");
|
fail("No exception throwed");
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testDirectoryExists() throws IOException {
|
public void testDirectoryExists() throws IOException {
|
||||||
final String SUBDIRECTORY_NAME = "ad" + FS + "sda" + FS + "asd";
|
final String SUBDIRECTORY_NAME = "ad" + FS + "sda" + FS + "asd";
|
||||||
boolean result;
|
boolean result;
|
||||||
|
@ -188,21 +181,20 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
result = storageStrategy.directoryExists(CONTAINER_NAME, null);
|
result = storageStrategy.directoryExists(CONTAINER_NAME, null);
|
||||||
assertFalse(result, "Directory exist");
|
assertFalse(result, "Directory exist");
|
||||||
|
|
||||||
//create the container
|
// create the container
|
||||||
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
|
||||||
//check if exists
|
// check if exists
|
||||||
result = storageStrategy.directoryExists(CONTAINER_NAME, null);
|
result = storageStrategy.directoryExists(CONTAINER_NAME, null);
|
||||||
assertTrue(result, "Directory doesn't exist");
|
assertTrue(result, "Directory doesn't exist");
|
||||||
result = storageStrategy.directoryExists(CONTAINER_NAME + FS, null);
|
result = storageStrategy.directoryExists(CONTAINER_NAME + FS, null);
|
||||||
assertTrue(result, "Directory doesn't exist");
|
assertTrue(result, "Directory doesn't exist");
|
||||||
|
|
||||||
|
|
||||||
result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME);
|
result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME);
|
||||||
assertFalse(result, "Directory exist");
|
assertFalse(result, "Directory exist");
|
||||||
|
|
||||||
//create subdirs inside the container
|
// create subdirs inside the container
|
||||||
TestUtils.createContainerAsDirectory(CONTAINER_NAME + FS + SUBDIRECTORY_NAME);
|
TestUtils.createContainerAsDirectory(CONTAINER_NAME + FS + SUBDIRECTORY_NAME);
|
||||||
//check if exists
|
// check if exists
|
||||||
result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME);
|
result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME);
|
||||||
assertTrue(result, "Directory doesn't exist");
|
assertTrue(result, "Directory doesn't exist");
|
||||||
result = storageStrategy.directoryExists(CONTAINER_NAME, FS + SUBDIRECTORY_NAME);
|
result = storageStrategy.directoryExists(CONTAINER_NAME, FS + SUBDIRECTORY_NAME);
|
||||||
|
@ -214,83 +206,73 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testClearContainer() throws IOException {
|
||||||
public void testClearContainer() throws IOException{
|
|
||||||
storageStrategy.createContainer(CONTAINER_NAME);
|
storageStrategy.createContainer(CONTAINER_NAME);
|
||||||
Set<String> blobs = TestUtils.createBlobsInContainer(
|
Set<String> blobs = TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
|
||||||
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg")}
|
// test if file exits
|
||||||
);
|
for (String blob : blobs) {
|
||||||
//test if file exits
|
|
||||||
for(String blob:blobs) {
|
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear the container
|
// clear the container
|
||||||
storageStrategy.clearContainer(CONTAINER_NAME);
|
storageStrategy.clearContainer(CONTAINER_NAME);
|
||||||
//test if container still exits
|
// test if container still exits
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
||||||
//test if file was cleared
|
// test if file was cleared
|
||||||
for(String blob:blobs) {
|
for (String blob : blobs) {
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testClearContainer_NotExistingContainer() throws IOException {
|
||||||
public void testClearContainer_NotExistingContainer() throws IOException{
|
// test if container still exits
|
||||||
//test if container still exits
|
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||||
//clear the container
|
// clear the container
|
||||||
storageStrategy.clearContainer(CONTAINER_NAME);
|
storageStrategy.clearContainer(CONTAINER_NAME);
|
||||||
//test if container still exits
|
// test if container still exits
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testClearContainerAndThenDeleteContainer() throws IOException {
|
||||||
public void testClearContainerAndThenDeleteContainer() throws IOException{
|
|
||||||
storageStrategy.createContainer(CONTAINER_NAME);
|
storageStrategy.createContainer(CONTAINER_NAME);
|
||||||
Set<String> blobs = TestUtils.createBlobsInContainer(
|
Set<String> blobs = TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
|
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
|
||||||
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg")}
|
// test if file exits
|
||||||
);
|
for (String blob : blobs) {
|
||||||
//test if file exits
|
|
||||||
for(String blob:blobs) {
|
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//clear the container
|
// clear the container
|
||||||
storageStrategy.clearContainer(CONTAINER_NAME);
|
storageStrategy.clearContainer(CONTAINER_NAME);
|
||||||
//test if container still exits
|
// test if container still exits
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
|
||||||
//test if file was cleared
|
// test if file was cleared
|
||||||
for(String blob:blobs) {
|
for (String blob : blobs) {
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, false);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete the container
|
// delete the container
|
||||||
storageStrategy.deleteContainer(CONTAINER_NAME);
|
storageStrategy.deleteContainer(CONTAINER_NAME);
|
||||||
//test if container still exits
|
// test if container still exits
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||||
assertFalse(storageStrategy.containerExists(CONTAINER_NAME), "Container still exists");
|
assertFalse(storageStrategy.containerExists(CONTAINER_NAME), "Container still exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testDeleteContainer() throws IOException {
|
public void testDeleteContainer() throws IOException {
|
||||||
final String BLOB_KEY1 = "blobName.jpg";
|
final String BLOB_KEY1 = "blobName.jpg";
|
||||||
final String BLOB_KEY2 = "aa" + FS + "bb" + FS + "cc" + FS + "dd" + FS + "ee" + FS + "ff" + FS + "23" + FS + "blobName.jpg";
|
final String BLOB_KEY2 = "aa" + FS + "bb" + FS + "cc" + FS + "dd" + FS + "ee" + FS + "ff" + FS + "23" + FS
|
||||||
|
+ "blobName.jpg";
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
result = storageStrategy.createContainer(CONTAINER_NAME);
|
result = storageStrategy.createContainer(CONTAINER_NAME);
|
||||||
|
|
||||||
//put data inside the container
|
// put data inside the container
|
||||||
TestUtils.createBlobsInContainer(
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] { BLOB_KEY1, BLOB_KEY2 });
|
||||||
CONTAINER_NAME,
|
|
||||||
new String[] {BLOB_KEY1, BLOB_KEY2}
|
|
||||||
);
|
|
||||||
|
|
||||||
storageStrategy.deleteContainer(CONTAINER_NAME);
|
storageStrategy.deleteContainer(CONTAINER_NAME);
|
||||||
assertTrue(result, "Cannot delete container");
|
assertTrue(result, "Cannot delete container");
|
||||||
|
@ -315,16 +297,15 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGetAllContainerNames() {
|
public void testGetAllContainerNames() {
|
||||||
Iterable<String> resultList;
|
Iterable<String> resultList;
|
||||||
|
|
||||||
//no container
|
// no container
|
||||||
resultList = storageStrategy.getAllContainerNames();
|
resultList = storageStrategy.getAllContainerNames();
|
||||||
assertNotNull(resultList, "Result is null");
|
assertNotNull(resultList, "Result is null");
|
||||||
assertFalse(resultList.iterator().hasNext(), "Containers detected");
|
assertFalse(resultList.iterator().hasNext(), "Containers detected");
|
||||||
|
|
||||||
//create containers
|
// create containers
|
||||||
storageStrategy.createContainer(CONTAINER_NAME + "1");
|
storageStrategy.createContainer(CONTAINER_NAME + "1");
|
||||||
storageStrategy.createContainer(CONTAINER_NAME + "2");
|
storageStrategy.createContainer(CONTAINER_NAME + "2");
|
||||||
storageStrategy.createContainer(CONTAINER_NAME + "3");
|
storageStrategy.createContainer(CONTAINER_NAME + "3");
|
||||||
|
@ -332,7 +313,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
List<String> containers = new ArrayList<String>();
|
List<String> containers = new ArrayList<String>();
|
||||||
resultList = storageStrategy.getAllContainerNames();
|
resultList = storageStrategy.getAllContainerNames();
|
||||||
Iterator<String> containersIterator = resultList.iterator();
|
Iterator<String> containersIterator = resultList.iterator();
|
||||||
while(containersIterator.hasNext()){
|
while (containersIterator.hasNext()) {
|
||||||
containers.add(containersIterator.next());
|
containers.add(containersIterator.next());
|
||||||
}
|
}
|
||||||
assertEquals(containers.size(), 3, "Different containers number");
|
assertEquals(containers.size(), 3, "Different containers number");
|
||||||
|
@ -341,8 +322,7 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertTrue(containers.contains(CONTAINER_NAME + "3"), "Containers doesn't exist");
|
assertTrue(containers.contains(CONTAINER_NAME + "3"), "Containers doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testContainerExists() {
|
||||||
public void testContainerExists(){
|
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
|
||||||
|
@ -353,7 +333,6 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertTrue(result, "Container exists");
|
assertTrue(result, "Container exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testNewBlob() {
|
public void testNewBlob() {
|
||||||
String blobKey;
|
String blobKey;
|
||||||
Blob newBlob;
|
Blob newBlob;
|
||||||
|
@ -373,7 +352,6 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertEquals(newBlob.getMetadata().getName(), blobKey, "Created blob name is different");
|
assertEquals(newBlob.getMetadata().getName(), blobKey, "Created blob name is different");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testWritePayloadOnFile() throws IOException {
|
public void testWritePayloadOnFile() throws IOException {
|
||||||
String blobKey;
|
String blobKey;
|
||||||
File sourceFile;
|
File sourceFile;
|
||||||
|
@ -382,9 +360,9 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img");
|
blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img");
|
||||||
sourceFile = TestUtils.getImageForBlobPayload();
|
sourceFile = TestUtils.getImageForBlobPayload();
|
||||||
filePayload = new FilePayload(sourceFile);
|
filePayload = new FilePayload(sourceFile);
|
||||||
//write files
|
// write files
|
||||||
storageStrategy.writePayloadOnFile(CONTAINER_NAME, blobKey, filePayload);
|
storageStrategy.writePayloadOnFile(CONTAINER_NAME, blobKey, filePayload);
|
||||||
//verify that the files is equal
|
// verify that the files is equal
|
||||||
String blobFullPath = TARGET_CONTAINER_NAME + FS + blobKey;
|
String blobFullPath = TARGET_CONTAINER_NAME + FS + blobKey;
|
||||||
InputStream expectedInput = new FileInputStream(sourceFile);
|
InputStream expectedInput = new FileInputStream(sourceFile);
|
||||||
InputStream currentInput = new FileInputStream(blobFullPath);
|
InputStream currentInput = new FileInputStream(blobFullPath);
|
||||||
|
@ -400,7 +378,6 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGetFileForBlobKey() {
|
public void testGetFileForBlobKey() {
|
||||||
String blobKey;
|
String blobKey;
|
||||||
File fileForPayload;
|
File fileForPayload;
|
||||||
|
@ -416,23 +393,18 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertEquals(fileForPayload.getAbsolutePath(), fullPath + blobKey, "Wrong file path");
|
assertEquals(fileForPayload.getAbsolutePath(), fullPath + blobKey, "Wrong file path");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetFileForBlobKey_AbsolutePath() throws IOException {
|
||||||
public void testGetFileForBlobKey_AbsolutePath()
|
|
||||||
throws IOException {
|
|
||||||
String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS;
|
String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS;
|
||||||
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS;
|
||||||
|
|
||||||
//create storageStrategy with an absolute path
|
// create storageStrategy with an absolute path
|
||||||
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl(
|
||||||
new Blob.Factory() {
|
new Provider<BlobBuilder>() {
|
||||||
@Override
|
@Override
|
||||||
public Blob create(MutableBlobMetadata metadata) {
|
public BlobBuilder get() {
|
||||||
return new BlobImpl(metadata != null ? metadata : new MutableBlobMetadataImpl());
|
return new BlobBuilderImpl();
|
||||||
}
|
}
|
||||||
},
|
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
|
||||||
absoluteBasePath,
|
|
||||||
new FilesystemContainerNameValidatorImpl(),
|
|
||||||
new FilesystemBlobKeyValidatorImpl());
|
|
||||||
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
TestUtils.cleanDirectoryContent(absoluteContainerPath);
|
||||||
|
|
||||||
String blobKey;
|
String blobKey;
|
||||||
|
@ -448,46 +420,40 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
assertEquals(fileForPayload.getAbsolutePath(), absoluteContainerPath + blobKey, "Wrong file path");
|
assertEquals(fileForPayload.getAbsolutePath(), absoluteContainerPath + blobKey, "Wrong file path");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBlobExists() throws IOException {
|
public void testBlobExists() throws IOException {
|
||||||
String[] sourceBlobKeys = new String[]{
|
String[] sourceBlobKeys = new String[] { TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("blobExists-", ".jpg"),
|
TestUtils.createRandomBlobKey("afasd" + FS + "asdma" + FS + "blobExists-", ".jpg") };
|
||||||
TestUtils.createRandomBlobKey("afasd" + FS + "asdma" + FS + "blobExists-", ".jpg")
|
|
||||||
};
|
|
||||||
|
|
||||||
for(String blobKey:sourceBlobKeys) {
|
for (String blobKey : sourceBlobKeys) {
|
||||||
assertFalse(storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " exists");
|
assertFalse(storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " exists");
|
||||||
}
|
}
|
||||||
TestUtils.createBlobsInContainer(CONTAINER_NAME, sourceBlobKeys);
|
TestUtils.createBlobsInContainer(CONTAINER_NAME, sourceBlobKeys);
|
||||||
for(String blobKey:sourceBlobKeys) {
|
for (String blobKey : sourceBlobKeys) {
|
||||||
assertTrue(storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " doesn't exist");
|
assertTrue(storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " doesn't exist");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testRemoveBlob() throws IOException {
|
public void testRemoveBlob() throws IOException {
|
||||||
storageStrategy.createContainer(CONTAINER_NAME);
|
storageStrategy.createContainer(CONTAINER_NAME);
|
||||||
Set<String> blobKeys = TestUtils.createBlobsInContainer(
|
Set<String> blobKeys = TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
|
||||||
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg")
|
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> remainingBlobKeys = new HashSet<String>();
|
Set<String> remainingBlobKeys = new HashSet<String>();
|
||||||
for(String key:blobKeys) {
|
for (String key : blobKeys) {
|
||||||
remainingBlobKeys.add(key);
|
remainingBlobKeys.add(key);
|
||||||
}
|
}
|
||||||
for (String blobKeyToRemove:blobKeys) {
|
for (String blobKeyToRemove : blobKeys) {
|
||||||
storageStrategy.removeBlob(CONTAINER_NAME, blobKeyToRemove);
|
storageStrategy.removeBlob(CONTAINER_NAME, blobKeyToRemove);
|
||||||
//checks if the blob was removed
|
// checks if the blob was removed
|
||||||
TestUtils.fileExists(blobKeyToRemove, false);
|
TestUtils.fileExists(blobKeyToRemove, false);
|
||||||
remainingBlobKeys.remove(blobKeyToRemove);
|
remainingBlobKeys.remove(blobKeyToRemove);
|
||||||
//checks if all other blobs still exists
|
// checks if all other blobs still exists
|
||||||
for(String remainingBlobKey:remainingBlobKeys) {
|
for (String remainingBlobKey : remainingBlobKeys) {
|
||||||
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + remainingBlobKey, true);
|
TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + remainingBlobKey, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,40 +468,36 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
storageStrategy.removeBlob(CONTAINER_NAME, "sdfsdfsdfasd");
|
storageStrategy.removeBlob(CONTAINER_NAME, "sdfsdfsdfasd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGetBlobKeysInsideContainer() throws IOException {
|
public void testGetBlobKeysInsideContainer() throws IOException {
|
||||||
Iterable<String> resultList;
|
Iterable<String> resultList;
|
||||||
|
|
||||||
//no container
|
// no container
|
||||||
resultList = storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
resultList = storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
||||||
assertNotNull(resultList, "Result is null");
|
assertNotNull(resultList, "Result is null");
|
||||||
assertFalse(resultList.iterator().hasNext(), "Blobs detected");
|
assertFalse(resultList.iterator().hasNext(), "Blobs detected");
|
||||||
|
|
||||||
//create blobs
|
// create blobs
|
||||||
storageStrategy.createContainer(CONTAINER_NAME);
|
storageStrategy.createContainer(CONTAINER_NAME);
|
||||||
Set<String> createBlobKeys = TestUtils.createBlobsInContainer(
|
Set<String> createBlobKeys = TestUtils.createBlobsInContainer(
|
||||||
CONTAINER_NAME,
|
CONTAINER_NAME,
|
||||||
new String[]{
|
new String[] { TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
|
||||||
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
|
||||||
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg")
|
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
|
||||||
});
|
|
||||||
storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
||||||
|
|
||||||
List<String> retrievedBlobKeys = new ArrayList<String>();
|
List<String> retrievedBlobKeys = new ArrayList<String>();
|
||||||
resultList = storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
resultList = storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME);
|
||||||
Iterator<String> containersIterator = resultList.iterator();
|
Iterator<String> containersIterator = resultList.iterator();
|
||||||
while(containersIterator.hasNext()){
|
while (containersIterator.hasNext()) {
|
||||||
retrievedBlobKeys.add(containersIterator.next());
|
retrievedBlobKeys.add(containersIterator.next());
|
||||||
}
|
}
|
||||||
assertEquals(retrievedBlobKeys.size(), createBlobKeys.size(), "Different blobs number");
|
assertEquals(retrievedBlobKeys.size(), createBlobKeys.size(), "Different blobs number");
|
||||||
for(String createdBlobKey:createBlobKeys) {
|
for (String createdBlobKey : createBlobKeys) {
|
||||||
assertTrue(retrievedBlobKeys.contains(createdBlobKey), "Blob " + createdBlobKey + " not found");
|
assertTrue(retrievedBlobKeys.contains(createdBlobKey), "Blob " + createdBlobKey + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCountsBlob() {
|
public void testCountsBlob() {
|
||||||
try {
|
try {
|
||||||
storageStrategy.countBlobs(CONTAINER_NAME, ListContainerOptions.NONE);
|
storageStrategy.countBlobs(CONTAINER_NAME, ListContainerOptions.NONE);
|
||||||
|
@ -544,26 +506,27 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testInvalidBlobKey() {
|
public void testInvalidBlobKey() {
|
||||||
try {
|
try {
|
||||||
storageStrategy.newBlob(FS + "test.jpg");
|
storageStrategy.newBlob(FS + "test.jpg");
|
||||||
fail("Wrong blob key not recognized");
|
fail("Wrong blob key not recognized");
|
||||||
} catch (IllegalArgumentException e) {}
|
} catch (IllegalArgumentException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInvalidContainerName() {
|
public void testInvalidContainerName() {
|
||||||
try {
|
try {
|
||||||
storageStrategy.createContainer("file" + FS + "system");
|
storageStrategy.createContainer("file" + FS + "system");
|
||||||
fail("Wrong container name not recognized");
|
fail("Wrong container name not recognized");
|
||||||
} catch (IllegalArgumentException e) {}
|
} catch (IllegalArgumentException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------- Private methods
|
// ---------------------------------------------------------- Private methods
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates an absolute directory path that depends on operative system
|
* Calculates an absolute directory path that depends on operative system
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getAbsoluteDirectory() throws IOException {
|
private String getAbsoluteDirectory() throws IOException {
|
||||||
|
@ -573,5 +536,4 @@ public class FilesystemStorageStrategyImplTest {
|
||||||
return tempAbsolutePath;
|
return tempAbsolutePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import com.google.common.base.Function;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ObjectToBlob implements Function<S3Object, Blob> {
|
public class ObjectToBlob implements Function<S3Object, Blob> {
|
||||||
private final Blob.Factory blobFactory;
|
private final Factory blobFactory;
|
||||||
private final ObjectToBlobMetadata object2BlobMd;
|
private final ObjectToBlobMetadata object2BlobMd;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
|
@ -35,7 +35,7 @@ import com.google.common.base.Function;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ObjectToBlob implements Function<SwiftObject, Blob> {
|
public class ObjectToBlob implements Function<SwiftObject, Blob> {
|
||||||
private final Blob.Factory blobFactory;
|
private final Factory blobFactory;
|
||||||
private final ObjectToBlobMetadata object2BlobMd;
|
private final ObjectToBlobMetadata object2BlobMd;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
|
@ -47,8 +48,14 @@ public interface AsyncBlobStore {
|
||||||
/**
|
/**
|
||||||
* @see BlobStore#newBlob
|
* @see BlobStore#newBlob
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
Blob newBlob(String name);
|
Blob newBlob(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see BlobStore#blobBuilder
|
||||||
|
*/
|
||||||
|
BlobBuilder blobBuilder(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BlobStore#listAssignableLocations
|
* @see BlobStore#listAssignableLocations
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.jclouds.blobstore;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.internal.BlobMapImpl;
|
import org.jclouds.blobstore.internal.BlobMapImpl;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
|
||||||
|
@ -34,9 +35,19 @@ 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> {
|
||||||
|
/**
|
||||||
|
* @see #blobBuilder
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
Blob newBlob(String name);
|
Blob newBlob(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return builder for creating new {@link Blob}s
|
||||||
|
*/
|
||||||
|
BlobBuilder blobBuilder();
|
||||||
|
|
||||||
public static interface Factory {
|
public static interface Factory {
|
||||||
BlobMap create(String containerName, ListContainerOptions options);
|
BlobMap create(String containerName, ListContainerOptions options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Set;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
|
@ -47,9 +48,17 @@ public interface BlobStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new blob with the specified name.
|
* creates a new blob with the specified name.
|
||||||
|
* @see #blobBuilder
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
Blob newBlob(String name);
|
Blob newBlob(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return builder for creating new {@link Blob}s
|
||||||
|
*/
|
||||||
|
BlobBuilder blobBuilder(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The get locations command returns all the valid locations for containers. A location has a
|
* The get locations command returns all the valid locations for containers. A location has a
|
||||||
* scope, which is typically region or zone. A region is a general area, like eu-west, where a
|
* scope, which is typically region or zone. A region is a general area, like eu-west, where a
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.blobstore;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.base.Throwables.getCausalChain;
|
import static com.google.common.base.Throwables.getCausalChain;
|
||||||
|
@ -125,7 +126,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
protected TransientAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto,
|
protected TransientAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto,
|
||||||
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
|
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
|
||||||
ConcurrentMap<String, Location> containerToLocation, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
ConcurrentMap<String, Location> containerToLocation, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Factory blobFactory, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
super(context, blobUtils, service, defaultLocation, locations);
|
||||||
|
@ -487,6 +488,8 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<String> putBlob(String containerName, Blob in) {
|
public ListenableFuture<String> putBlob(String containerName, Blob in) {
|
||||||
|
checkArgument(containerName != null, "containerName must be set");
|
||||||
|
checkArgument(in != null, "blob must be set");
|
||||||
ConcurrentMap<String, Blob> container = getContainerToBlobs().get(containerName);
|
ConcurrentMap<String, Blob> container = getContainerToBlobs().get(containerName);
|
||||||
if (container == null) {
|
if (container == null) {
|
||||||
new IllegalStateException("containerName not found: " + containerName);
|
new IllegalStateException("containerName not found: " + containerName);
|
||||||
|
@ -513,6 +516,8 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Blob createUpdatedCopyOfBlob(Blob in) {
|
protected Blob createUpdatedCopyOfBlob(Blob in) {
|
||||||
|
checkNotNull(in, "blob");
|
||||||
|
checkNotNull(in.getPayload(), "blob.payload");
|
||||||
ByteArrayPayload payload = (in.getPayload() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(in
|
ByteArrayPayload payload = (in.getPayload() instanceof ByteArrayPayload) ? ByteArrayPayload.class.cast(in
|
||||||
.getPayload()) : null;
|
.getPayload()) : null;
|
||||||
if (payload == null)
|
if (payload == null)
|
||||||
|
|
|
@ -20,11 +20,12 @@
|
||||||
package org.jclouds.blobstore.config;
|
package org.jclouds.blobstore.config;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.InputStreamMap;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.internal.BlobMapImpl;
|
import org.jclouds.blobstore.internal.BlobMapImpl;
|
||||||
import org.jclouds.blobstore.internal.InputStreamMapImpl;
|
import org.jclouds.blobstore.internal.InputStreamMapImpl;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
@ -65,10 +66,12 @@ public class BlobStoreMapModule extends AbstractModule {
|
||||||
PutBlobsStrategy putBlobsStrategy;
|
PutBlobsStrategy putBlobsStrategy;
|
||||||
@Inject
|
@Inject
|
||||||
ListContainerAndRecurseThroughFolders listStrategy;
|
ListContainerAndRecurseThroughFolders listStrategy;
|
||||||
|
@Inject
|
||||||
|
Provider<BlobBuilder> blobBuilders;
|
||||||
|
|
||||||
public BlobMap create(String containerName, ListContainerOptions options) {
|
public BlobMap create(String containerName, ListContainerOptions options) {
|
||||||
return new BlobMapImpl(connection, getAllBlobs, containsValueStrategy, putBlobsStrategy,
|
return new BlobMapImpl(connection, getAllBlobs, containsValueStrategy, putBlobsStrategy, listStrategy,
|
||||||
listStrategy, containerName, options);
|
containerName, options, blobBuilders);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,7 +80,7 @@ public class BlobStoreMapModule extends AbstractModule {
|
||||||
@Inject
|
@Inject
|
||||||
BlobStore connection;
|
BlobStore connection;
|
||||||
@Inject
|
@Inject
|
||||||
Blob.Factory blobFactory;
|
Provider<BlobBuilder> blobBuilders;
|
||||||
@Inject
|
@Inject
|
||||||
GetBlobsInListStrategy getAllBlobs;
|
GetBlobsInListStrategy getAllBlobs;
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -90,9 +93,8 @@ public class BlobStoreMapModule extends AbstractModule {
|
||||||
ListContainerAndRecurseThroughFolders listStrategy;
|
ListContainerAndRecurseThroughFolders listStrategy;
|
||||||
|
|
||||||
public InputStreamMap create(String containerName, ListContainerOptions options) {
|
public InputStreamMap create(String containerName, ListContainerOptions options) {
|
||||||
return new InputStreamMapImpl(connection, blobFactory, getAllBlobs, listStrategy,
|
return new InputStreamMapImpl(connection, blobBuilders, getAllBlobs, listStrategy, containsValueStrategy,
|
||||||
containsValueStrategy, putBlobsStrategy, containerName, options,
|
putBlobsStrategy, containerName, options, crypto);
|
||||||
crypto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.blobstore.domain;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
|
|
||||||
|
import com.google.inject.ImplementedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* In case the name was confusing, this indeed builds a Blob.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@ImplementedBy(BlobBuilderImpl.class)
|
||||||
|
public interface BlobBuilder {
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* The name of the {@link Blob}. Typically refers to an http path.
|
||||||
|
*/
|
||||||
|
BlobBuilder name(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type
|
||||||
|
* overrides default type of {@link StorageType#BLOB}
|
||||||
|
*/
|
||||||
|
BlobBuilder type(StorageType type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param userMetadata
|
||||||
|
* User defined metadata associated with this {@link Blob}.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BlobBuilder userMetadata(Map<String, String> userMetadata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param payload
|
||||||
|
* payload you wish to construct the {@link Blob} with.
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder payload(Payload payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param payload
|
||||||
|
* payload you wish to construct the {@link Blob} with.
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder payload(InputStream payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param payload
|
||||||
|
* payload you wish to construct the {@link Blob} with.
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder payload(byte[] payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param payload
|
||||||
|
* payload you wish to construct the {@link Blob} with.
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder payload(String payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param payload
|
||||||
|
* payload you wish to construct the {@link Blob} with.
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder payload(File payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This makes a blob from the currently configured parameters.
|
||||||
|
*
|
||||||
|
* @return a new blob from the current parameters
|
||||||
|
*/
|
||||||
|
Blob build();
|
||||||
|
|
||||||
|
public interface PayloadBlobBuilder extends BlobBuilder {
|
||||||
|
|
||||||
|
PayloadBlobBuilder contentLength(long contentLength);
|
||||||
|
|
||||||
|
PayloadBlobBuilder contentMD5(byte[] md5);
|
||||||
|
|
||||||
|
PayloadBlobBuilder contentType(String contentType);
|
||||||
|
|
||||||
|
PayloadBlobBuilder contentDisposition(String contentDisposition);
|
||||||
|
|
||||||
|
PayloadBlobBuilder contentLanguage(String contentLanguage);
|
||||||
|
|
||||||
|
PayloadBlobBuilder contentEncoding(String contentEncoding);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @see Payloads#calculateMD5
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder calculateMD5() throws IOException;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,229 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.blobstore.domain.internal;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.io.Payloads.newPayload;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
|
import org.jclouds.blobstore.domain.StorageType;
|
||||||
|
import org.jclouds.crypto.Crypto;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class BlobBuilderImpl implements BlobBuilder {
|
||||||
|
|
||||||
|
private Payload payload;
|
||||||
|
private String name;
|
||||||
|
private Map<String, String> userMetadata = Maps.newLinkedHashMap();
|
||||||
|
private StorageType type = StorageType.BLOB;
|
||||||
|
@Inject
|
||||||
|
private Crypto crypto;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder type(StorageType type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder userMetadata(Map<String, String> userMetadata) {
|
||||||
|
this.userMetadata = Maps.newLinkedHashMap(checkNotNull(userMetadata, "userMetadata"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(Payload payload) {
|
||||||
|
this.payload = payload;
|
||||||
|
return new PayloadBlobBuilderImpl(this, payload, crypto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(InputStream data) {
|
||||||
|
return payload(newPayload(checkNotNull(data, "data")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(byte[] data) {
|
||||||
|
return payload(newPayload(checkNotNull(data, "data")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(String data) {
|
||||||
|
return payload(newPayload(checkNotNull(data, "data")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(File data) {
|
||||||
|
return payload(newPayload(checkNotNull(data, "data")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blob build() {
|
||||||
|
Blob blob = new BlobImpl(new MutableBlobMetadataImpl());
|
||||||
|
if (name != null)
|
||||||
|
blob.getMetadata().setName(name);
|
||||||
|
if (payload != null)
|
||||||
|
blob.setPayload(payload);
|
||||||
|
blob.getMetadata().setUserMetadata(userMetadata);
|
||||||
|
blob.getMetadata().setType(type);
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PayloadBlobBuilderImpl implements PayloadBlobBuilder {
|
||||||
|
private final BlobBuilder builder;
|
||||||
|
private final Payload payload;
|
||||||
|
private MessageDigest digest;
|
||||||
|
|
||||||
|
public PayloadBlobBuilderImpl(BlobBuilder builder, Payload payload, @Nullable Crypto crypto) {
|
||||||
|
this.builder = checkNotNull(builder, "builder");
|
||||||
|
this.payload = checkNotNull(payload, "payload");
|
||||||
|
try {
|
||||||
|
this.digest = crypto != null ? crypto.md5() : MessageDigest.getInstance("MD5");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
this.digest = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder name(String name) {
|
||||||
|
return builder.name(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder type(StorageType type) {
|
||||||
|
return builder.type(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder userMetadata(Map<String, String> userMetadata) {
|
||||||
|
return builder.userMetadata(userMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(Payload payload) {
|
||||||
|
return builder.payload(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder calculateMD5() throws IOException {
|
||||||
|
return builder.payload(Payloads.calculateMD5(payload, digest));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(InputStream payload) {
|
||||||
|
return builder.payload(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(byte[] payload) {
|
||||||
|
return builder.payload(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(String payload) {
|
||||||
|
return builder.payload(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder payload(File payload) {
|
||||||
|
return builder.payload(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blob build() {
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder contentLength(long contentLength) {
|
||||||
|
payload.getContentMetadata().setContentLength(contentLength);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder contentMD5(byte[] md5) {
|
||||||
|
payload.getContentMetadata().setContentMD5(md5);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder contentType(String contentType) {
|
||||||
|
payload.getContentMetadata().setContentType(contentType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder contentDisposition(String contentDisposition) {
|
||||||
|
payload.getContentMetadata().setContentDisposition(contentDisposition);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder contentLanguage(String contentLanguage) {
|
||||||
|
payload.getContentMetadata().setContentLanguage(contentLanguage);
|
||||||
|
return this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder contentEncoding(String contentEncoding) {
|
||||||
|
payload.getContentMetadata().setContentEncoding(contentEncoding);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
@ -83,6 +84,14 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
||||||
return blobUtils.newBlob(name);
|
return blobUtils.newBlob(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* invokes {@link BlobUtilsImpl#blobBuilder }
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BlobBuilder blobBuilder(String name) {
|
||||||
|
return blobUtils.blobBuilder().name(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This implementation invokes
|
* This implementation invokes
|
||||||
* {@link #list(String,org.jclouds.blobstore.options.ListContainerOptions)}
|
* {@link #list(String,org.jclouds.blobstore.options.ListContainerOptions)}
|
||||||
|
|
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.blobstore.internal;
|
package org.jclouds.blobstore.internal;
|
||||||
|
|
||||||
|
import static com.google.common.base.Functions.identity;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.ListableMap;
|
import org.jclouds.blobstore.ListableMap;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
@ -39,9 +43,7 @@ import org.jclouds.blobstore.strategy.PutBlobsStrategy;
|
||||||
import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
|
import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements core Map functionality with a {@link BlobStore}
|
* Implements core Map functionality with a {@link BlobStore}
|
||||||
|
@ -88,17 +90,10 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class PassThrough<T> implements Function<T, T> {
|
|
||||||
public T apply(T from) {
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BaseBlobMap(BlobStore blobstore, GetBlobsInListStrategy getAllBlobs,
|
public BaseBlobMap(BlobStore blobstore, GetBlobsInListStrategy getAllBlobs,
|
||||||
ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
|
ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
|
||||||
ListContainerAndRecurseThroughFolders listStrategy, String containerName,
|
ListContainerAndRecurseThroughFolders listStrategy, String containerName, ListContainerOptions options) {
|
||||||
ListContainerOptions options) {
|
|
||||||
this.blobstore = checkNotNull(blobstore, "blobstore");
|
this.blobstore = checkNotNull(blobstore, "blobstore");
|
||||||
this.containerName = checkNotNull(containerName, "container");
|
this.containerName = checkNotNull(containerName, "container");
|
||||||
checkArgument(containerName.indexOf('/') == -1,
|
checkArgument(containerName.indexOf('/') == -1,
|
||||||
|
@ -107,7 +102,7 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
: new ImmutableListContainerOptions(options);
|
: new ImmutableListContainerOptions(options);
|
||||||
String dir = options.getDir();
|
String dir = options.getDir();
|
||||||
if (dir == null) {
|
if (dir == null) {
|
||||||
prefixer = new PassThrough<String>();
|
prefixer = identity();
|
||||||
pathStripper = prefixer;
|
pathStripper = prefixer;
|
||||||
} else {
|
} else {
|
||||||
prefixer = new PrefixKey(dir, "/");
|
prefixer = new PrefixKey(dir, "/");
|
||||||
|
@ -122,8 +117,7 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<java.util.Map.Entry<String, V>> entrySet() {
|
public Set<java.util.Map.Entry<String, V>> entrySet() {
|
||||||
return Sets.newHashSet(Iterables.transform(list(),
|
return ImmutableSet.copyOf(transform(list(), new Function<BlobMetadata, Map.Entry<String, V>>() {
|
||||||
new Function<BlobMetadata, Map.Entry<String, V>>() {
|
|
||||||
@Override
|
@Override
|
||||||
public java.util.Map.Entry<String, V> apply(BlobMetadata from) {
|
public java.util.Map.Entry<String, V> apply(BlobMetadata from) {
|
||||||
return new Entry(pathStripper.apply(from.getName()));
|
return new Entry(pathStripper.apply(from.getName()));
|
||||||
|
@ -187,7 +181,7 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> keySet() {
|
public Set<String> keySet() {
|
||||||
return Sets.newHashSet(Iterables.transform(list(), new Function<BlobMetadata, String>() {
|
return ImmutableSet.copyOf(transform(list(), new Function<BlobMetadata, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String apply(BlobMetadata from) {
|
public String apply(BlobMetadata from) {
|
||||||
return from.getName();
|
return from.getName();
|
||||||
|
@ -197,7 +191,7 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
String realKey = prefixer.apply(key.toString());
|
String realKey = prefixer.apply(checkNotNull(key, "key").toString());
|
||||||
return blobstore.blobExists(containerName, realKey);
|
return blobstore.blobExists(containerName, realKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,8 +201,7 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<? extends BlobMetadata> list() {
|
public Iterable<? extends BlobMetadata> list() {
|
||||||
return Iterables.transform(listStrategy.execute(containerName, options),
|
return transform(listStrategy.execute(containerName, options), new Function<BlobMetadata, BlobMetadata>() {
|
||||||
new Function<BlobMetadata, BlobMetadata>() {
|
|
||||||
public BlobMetadata apply(BlobMetadata from) {
|
public BlobMetadata apply(BlobMetadata from) {
|
||||||
MutableBlobMetadata md = new MutableBlobMetadataImpl(from);
|
MutableBlobMetadata md = new MutableBlobMetadataImpl(from);
|
||||||
if (options.getDir() != null)
|
if (options.getDir() != null)
|
||||||
|
@ -221,7 +214,7 @@ public abstract class BaseBlobMap<V> implements ListableMap<String, V> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "BaseBlobMap [containerName=" + containerName + ", options=" + options + "]";
|
return "[containerName=" + containerName + ", options=" + options + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,6 +30,7 @@ import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
|
@ -74,6 +75,14 @@ public abstract class BaseBlobStore implements BlobStore {
|
||||||
return blobUtils.newBlob(name);
|
return blobUtils.newBlob(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* invokes {@link BlobUtilsImpl#blobBuilder }
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BlobBuilder blobBuilder(String name) {
|
||||||
|
return blobUtils.blobBuilder().name(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This implementation invokes
|
* This implementation invokes
|
||||||
* {@link #list(String,org.jclouds.blobstore.options.ListContainerOptions)}
|
* {@link #list(String,org.jclouds.blobstore.options.ListContainerOptions)}
|
||||||
|
|
|
@ -19,22 +19,28 @@
|
||||||
|
|
||||||
package org.jclouds.blobstore.internal;
|
package org.jclouds.blobstore.internal;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
|
import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
|
||||||
import org.jclouds.blobstore.strategy.PutBlobsStrategy;
|
import org.jclouds.blobstore.strategy.PutBlobsStrategy;
|
||||||
import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
|
import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map representation of a live connection to a Blob Service.
|
* Map representation of a live connection to a Blob Service.
|
||||||
|
@ -45,36 +51,59 @@ import com.google.common.collect.Sets;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
|
public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
|
||||||
|
public static class CorrectBlobName implements Function<java.util.Map.Entry<? extends String, ? extends Blob>, Blob> {
|
||||||
|
private final Function<String, String> prefixer;
|
||||||
|
|
||||||
|
public CorrectBlobName(Function<String, String> prefixer) {
|
||||||
|
this.prefixer = checkNotNull(prefixer, "prefixer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blob apply(java.util.Map.Entry<? extends String, ? extends Blob> arg0) {
|
||||||
|
return apply(arg0.getKey(), arg0.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Blob apply(String key, Blob blob) {
|
||||||
|
blob.getMetadata().setName(prefixer.apply(key));
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final CorrectBlobName correctBlobName;
|
||||||
|
private final Provider<BlobBuilder> blobBuilders;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BlobMapImpl(BlobStore blobstore, GetBlobsInListStrategy getAllBlobs,
|
public BlobMapImpl(BlobStore blobstore, GetBlobsInListStrategy getAllBlobs,
|
||||||
ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
|
ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
|
||||||
ListContainerAndRecurseThroughFolders listStrategy, String containerName, ListContainerOptions options) {
|
ListContainerAndRecurseThroughFolders listStrategy, String containerName, ListContainerOptions options,
|
||||||
|
Provider<BlobBuilder> blobBuilders) {
|
||||||
super(blobstore, getAllBlobs, containsValueStrategy, putBlobsStrategy, listStrategy, containerName, options);
|
super(blobstore, getAllBlobs, containsValueStrategy, putBlobsStrategy, listStrategy, containerName, options);
|
||||||
|
this.correctBlobName = new CorrectBlobName(prefixer);
|
||||||
|
this.blobBuilders = checkNotNull(blobBuilders, "blobBuilders");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob get(Object key) {
|
public Blob get(Object key) {
|
||||||
String realKey = prefixer.apply(key.toString());
|
String realKey = prefixer.apply(checkNotNull(key, "key").toString());
|
||||||
Blob blob = blobstore.getBlob(containerName, realKey);
|
Blob blob = blobstore.getBlob(containerName, realKey);
|
||||||
return blob != null ? stripPrefix(blob) : null;
|
return blob != null ? stripPrefix(blob) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob put(String key, Blob value) {
|
public Blob put(String key, Blob value) {
|
||||||
Blob returnVal = getLastValue(key);
|
Blob returnVal = getLastValue(checkNotNull(key, "key"));
|
||||||
blobstore.putBlob(containerName, value);
|
blobstore.putBlob(containerName, correctBlobName.apply(key, value));
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(Map<? extends String, ? extends Blob> map) {
|
public void putAll(Map<? extends String, ? extends Blob> map) {
|
||||||
putBlobsStrategy.execute(containerName, map.values());
|
putBlobsStrategy.execute(containerName, transform(checkNotNull(map, "map").entrySet(), correctBlobName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob remove(Object key) {
|
public Blob remove(Object key) {
|
||||||
Blob old = getLastValue(key);
|
Blob old = getLastValue(checkNotNull(key, "key"));
|
||||||
String realKey = prefixer.apply(key.toString());
|
String realKey = prefixer.apply(key.toString());
|
||||||
blobstore.removeBlob(containerName, realKey);
|
blobstore.removeBlob(containerName, realKey);
|
||||||
return old;
|
return old;
|
||||||
|
@ -83,7 +112,7 @@ public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
|
||||||
private Blob getLastValue(Object key) {
|
private Blob getLastValue(Object key) {
|
||||||
Blob old;
|
Blob old;
|
||||||
try {
|
try {
|
||||||
old = get(key);
|
old = get(checkNotNull(key, "key"));
|
||||||
} catch (KeyNotFoundException e) {
|
} catch (KeyNotFoundException e) {
|
||||||
old = null;
|
old = null;
|
||||||
}
|
}
|
||||||
|
@ -92,12 +121,16 @@ public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Blob> values() {
|
public Collection<Blob> values() {
|
||||||
return Sets.newLinkedHashSet(getAllBlobs.execute(containerName, options));
|
return ImmutableSet.copyOf(getAllBlobs.execute(containerName, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob newBlob(String name) {
|
public Blob newBlob(String name) {
|
||||||
return blobstore.newBlob(name);
|
return blobBuilder().name(name).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder blobBuilder() {
|
||||||
|
return blobBuilders.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,13 @@ import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.InputStreamMap;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
|
import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
|
||||||
|
@ -66,12 +68,11 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
|
||||||
protected final Crypto crypto;
|
protected final Crypto crypto;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public InputStreamMapImpl(BlobStore connection, Blob.Factory blobFactory,
|
public InputStreamMapImpl(BlobStore connection, Provider<BlobBuilder> blobBuilders,
|
||||||
GetBlobsInListStrategy getAllBlobs, ListContainerAndRecurseThroughFolders listStrategy,
|
GetBlobsInListStrategy getAllBlobs, ListContainerAndRecurseThroughFolders listStrategy,
|
||||||
ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy,
|
ContainsValueInListStrategy containsValueStrategy, PutBlobsStrategy putBlobsStrategy, String containerName,
|
||||||
String containerName, ListContainerOptions options, Crypto crypto) {
|
ListContainerOptions options, Crypto crypto) {
|
||||||
super(connection, getAllBlobs, containsValueStrategy, putBlobsStrategy, listStrategy,
|
super(connection, getAllBlobs, containsValueStrategy, putBlobsStrategy, listStrategy, containerName, options);
|
||||||
containerName, options);
|
|
||||||
this.crypto = crypto;
|
this.crypto = crypto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +97,7 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<InputStream> values() {
|
public Collection<InputStream> values() {
|
||||||
return newArrayList(transform(getAllBlobs.execute(containerName, options),
|
return newArrayList(transform(getAllBlobs.execute(containerName, options), new Function<Blob, InputStream>() {
|
||||||
new Function<Blob, InputStream>() {
|
|
||||||
public InputStream apply(Blob from) {
|
public InputStream apply(Blob from) {
|
||||||
return getInputStreamOrNull(from);
|
return getInputStreamOrNull(from);
|
||||||
}
|
}
|
||||||
|
@ -132,8 +132,8 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void putAllInternal(Map<? extends String, ? extends Object> map) {
|
void putAllInternal(Map<? extends String, ? extends Object> map) {
|
||||||
putBlobsStrategy.execute(containerName, transform(map.entrySet(),
|
putBlobsStrategy.execute(containerName,
|
||||||
new Function<Map.Entry<? extends String, ? extends Object>, Blob>() {
|
transform(map.entrySet(), new Function<Map.Entry<? extends String, ? extends Object>, Blob>() {
|
||||||
@Override
|
@Override
|
||||||
public Blob apply(Map.Entry<? extends String, ? extends Object> from) {
|
public Blob apply(Map.Entry<? extends String, ? extends Object> from) {
|
||||||
String name = from.getKey();
|
String name = from.getKey();
|
||||||
|
@ -146,8 +146,7 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Blob newBlobWithMD5(String name, Object value) {
|
Blob newBlobWithMD5(String name, Object value) {
|
||||||
Blob blob = blobstore.newBlob(prefixer.apply(name));
|
Blob blob = blobstore.blobBuilder(prefixer.apply(name)).payload(newPayload(value)).build();
|
||||||
blob.setPayload(newPayload(value));
|
|
||||||
try {
|
try {
|
||||||
Payloads.calculateMD5(blob, crypto.md5());
|
Payloads.calculateMD5(blob, crypto.md5());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -19,15 +19,15 @@
|
||||||
|
|
||||||
package org.jclouds.blobstore.strategy.internal;
|
package org.jclouds.blobstore.strategy.internal;
|
||||||
|
|
||||||
|
import static org.jclouds.io.Payloads.newByteArrayPayload;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
import org.jclouds.blobstore.domain.StorageType;
|
||||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||||
import org.jclouds.blobstore.strategy.MkdirStrategy;
|
import org.jclouds.blobstore.strategy.MkdirStrategy;
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
@ -44,18 +44,17 @@ public class MarkerFileMkdirStrategy implements MkdirStrategy {
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
@Named(BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX)
|
@Named(BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX)
|
||||||
protected String directorySuffix = "";
|
protected String directorySuffix = "";
|
||||||
private final BlobStore connection;
|
private final BlobStore blobStore;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MarkerFileMkdirStrategy(BlobStore connection) {
|
MarkerFileMkdirStrategy(BlobStore blobStore) {
|
||||||
this.connection = connection;
|
this.blobStore = blobStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(String containerName, String directory) {
|
public void execute(String containerName, String directory) {
|
||||||
Blob blob = connection.newBlob(directory + directorySuffix);
|
blobStore.putBlob(
|
||||||
blob.setPayload(Payloads.newByteArrayPayload(new byte[] {}));
|
containerName,
|
||||||
blob.getPayload().getContentMetadata().setContentType("application/directory");
|
blobStore.blobBuilder(directory + directorySuffix).type(StorageType.RELATIVE_PATH)
|
||||||
blob.getMetadata().setType(StorageType.RELATIVE_PATH);
|
.payload(newByteArrayPayload(new byte[] {})).contentType("application/directory").build());
|
||||||
connection.putBlob(containerName, blob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -68,7 +68,7 @@ public class PutBlobsStrategyImpl implements PutBlobsStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(String containerName, Iterable<? extends Blob> blobs) {
|
public void execute(String containerName, Iterable<? extends Blob> blobs) {
|
||||||
Map<Blob, Future<?>> responses = Maps.newHashMap();
|
Map<Blob, Future<?>> responses = Maps.newLinkedHashMap();
|
||||||
for (Blob blob : blobs) {
|
for (Blob blob : blobs) {
|
||||||
responses.put(blob, ablobstore.putBlob(containerName, blob));
|
responses.put(blob, ablobstore.putBlob(containerName, blob));
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,8 @@ public class BlobStoreUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Blob newBlob(BlobStore blobStore, StorageMetadata blobMeta) {
|
public static Blob newBlob(BlobStore blobStore, StorageMetadata blobMeta) {
|
||||||
Blob blob = checkNotNull(blobStore, "blobStore").newBlob(checkNotNull(blobMeta, "blobMeta").getName());
|
Blob blob = checkNotNull(blobStore, "blobStore").blobBuilder(checkNotNull(blobMeta, "blobMeta").getName())
|
||||||
|
.userMetadata(blobMeta.getUserMetadata()).build();
|
||||||
if (blobMeta instanceof BlobMetadata) {
|
if (blobMeta instanceof BlobMetadata) {
|
||||||
HttpUtils.copy(((BlobMetadata) blobMeta).getContentMetadata(), blob.getMetadata().getContentMetadata());
|
HttpUtils.copy(((BlobMetadata) blobMeta).getContentMetadata(), blob.getMetadata().getContentMetadata());
|
||||||
}
|
}
|
||||||
|
@ -89,7 +90,6 @@ public class BlobStoreUtils {
|
||||||
blob.getMetadata().setLastModified(blobMeta.getLastModified());
|
blob.getMetadata().setLastModified(blobMeta.getLastModified());
|
||||||
blob.getMetadata().setLocation(blobMeta.getLocation());
|
blob.getMetadata().setLocation(blobMeta.getLocation());
|
||||||
blob.getMetadata().setUri(blobMeta.getUri());
|
blob.getMetadata().setUri(blobMeta.getUri());
|
||||||
blob.getMetadata().setUserMetadata(blobMeta.getUserMetadata());
|
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.jclouds.blobstore.util;
|
package org.jclouds.blobstore.util;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ import com.google.inject.ImplementedBy;
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(BlobUtilsImpl.class)
|
@ImplementedBy(BlobUtilsImpl.class)
|
||||||
public interface BlobUtils {
|
public interface BlobUtils {
|
||||||
|
BlobBuilder blobBuilder();
|
||||||
|
|
||||||
Blob newBlob(String name);
|
Blob newBlob(String name);
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,11 @@ package org.jclouds.blobstore.util.internal;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.ClearListStrategy;
|
import org.jclouds.blobstore.strategy.ClearListStrategy;
|
||||||
import org.jclouds.blobstore.strategy.CountListStrategy;
|
import org.jclouds.blobstore.strategy.CountListStrategy;
|
||||||
|
@ -41,7 +43,7 @@ import org.jclouds.blobstore.util.BlobUtils;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BlobUtilsImpl implements BlobUtils {
|
public class BlobUtilsImpl implements BlobUtils {
|
||||||
|
|
||||||
protected final Blob.Factory blobFactory;
|
protected final Provider<BlobBuilder> blobBuilders;
|
||||||
protected final ClearListStrategy clearContainerStrategy;
|
protected final ClearListStrategy clearContainerStrategy;
|
||||||
protected final GetDirectoryStrategy getDirectoryStrategy;
|
protected final GetDirectoryStrategy getDirectoryStrategy;
|
||||||
protected final MkdirStrategy mkdirStrategy;
|
protected final MkdirStrategy mkdirStrategy;
|
||||||
|
@ -49,10 +51,10 @@ public class BlobUtilsImpl implements BlobUtils {
|
||||||
protected final CountListStrategy countBlobsStrategy;
|
protected final CountListStrategy countBlobsStrategy;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BlobUtilsImpl(Blob.Factory blobFactory, ClearListStrategy clearContainerStrategy,
|
protected BlobUtilsImpl(Provider<BlobBuilder> blobBuilders, ClearListStrategy clearContainerStrategy,
|
||||||
GetDirectoryStrategy getDirectoryStrategy, MkdirStrategy mkdirStrategy,
|
GetDirectoryStrategy getDirectoryStrategy, MkdirStrategy mkdirStrategy, CountListStrategy countBlobsStrategy,
|
||||||
CountListStrategy countBlobsStrategy, DeleteDirectoryStrategy rmDirStrategy) {
|
DeleteDirectoryStrategy rmDirStrategy) {
|
||||||
this.blobFactory = checkNotNull(blobFactory, "blobFactory");
|
this.blobBuilders = checkNotNull(blobBuilders, "blobBuilders");
|
||||||
this.clearContainerStrategy = checkNotNull(clearContainerStrategy, "clearContainerStrategy");
|
this.clearContainerStrategy = checkNotNull(clearContainerStrategy, "clearContainerStrategy");
|
||||||
this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, "getDirectoryStrategy");
|
this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, "getDirectoryStrategy");
|
||||||
this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy");
|
this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy");
|
||||||
|
@ -60,10 +62,14 @@ public class BlobUtilsImpl implements BlobUtils {
|
||||||
this.countBlobsStrategy = checkNotNull(countBlobsStrategy, "countBlobsStrategy");
|
this.countBlobsStrategy = checkNotNull(countBlobsStrategy, "countBlobsStrategy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Blob newBlob(String name) {
|
public Blob newBlob(String name) {
|
||||||
Blob blob = blobFactory.create(null);
|
return blobBuilder().name(name).build();
|
||||||
blob.getMetadata().setName(name);
|
}
|
||||||
return blob;
|
|
||||||
|
@Override
|
||||||
|
public BlobBuilder blobBuilder() {
|
||||||
|
return blobBuilders.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean directoryExists(String containerName, String directory) {
|
public boolean directoryExists(String containerName, String directory) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.blobstore.integration;
|
package org.jclouds.blobstore.integration;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults;
|
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author James Murty
|
* @author James Murty
|
||||||
|
@ -44,22 +45,19 @@ public class TransientContainerIntegrationTest extends BaseContainerIntegrationT
|
||||||
public void testNotWithDetails() throws InterruptedException {
|
public void testNotWithDetails() throws InterruptedException {
|
||||||
|
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
|
|
||||||
Blob object = context.getBlobStore().newBlob(key);
|
|
||||||
object.setPayload(TEST_STRING);
|
|
||||||
object.getMetadata().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
|
||||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the
|
// NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the
|
||||||
// providers.
|
// providers.
|
||||||
object.getMetadata().getUserMetadata().put("Adrian", "powderpuff");
|
Blob blob = context.getBlobStore().blobBuilder("hello").userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||||
|
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).build();
|
||||||
|
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addBlobToContainer(containerName, object);
|
addBlobToContainer(containerName, blob);
|
||||||
validateContent(containerName, key);
|
validateContent(containerName, key);
|
||||||
|
|
||||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName,
|
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName, maxResults(1));
|
||||||
maxResults(1));
|
|
||||||
|
|
||||||
BlobMetadata metadata = (BlobMetadata) Iterables.getOnlyElement(container);
|
BlobMetadata metadata = (BlobMetadata) getOnlyElement(container);
|
||||||
// transient container should be lenient and not return metadata on undetailed listing.
|
// transient container should be lenient and not return metadata on undetailed listing.
|
||||||
|
|
||||||
assertEquals(metadata.getUserMetadata().size(), 0);
|
assertEquals(metadata.getUserMetadata().size(), 0);
|
||||||
|
|
|
@ -49,6 +49,7 @@ import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder.PayloadBlobBuilder;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.PageSet;
|
import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
|
@ -73,6 +74,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
@ -120,8 +122,8 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
Map<Integer, Future<?>> responses = Maps.newHashMap();
|
Map<Integer, Future<?>> responses = Maps.newHashMap();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
||||||
responses.put(i, Futures.compose(context.getAsyncBlobStore().getBlob(containerName, key),
|
responses.put(i,
|
||||||
new Function<Blob, Void>() {
|
Futures.compose(context.getAsyncBlobStore().getBlob(containerName, key), new Function<Blob, Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void apply(Blob from) {
|
public Void apply(Blob from) {
|
||||||
|
@ -147,13 +149,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadConstitution(String containerName, String key, String contentDisposition) throws IOException {
|
private void uploadConstitution(String containerName, String key, String contentDisposition) throws IOException {
|
||||||
Blob sourceObject = context.getBlobStore().newBlob(key);
|
context.getBlobStore().putBlob(
|
||||||
sourceObject.setPayload(oneHundredOneConstitutions.getInput());
|
containerName,
|
||||||
sourceObject.getMetadata().getContentMetadata().setContentType("text/plain");
|
context.getBlobStore().blobBuilder(key).payload(oneHundredOneConstitutions.getInput())
|
||||||
sourceObject.getMetadata().getContentMetadata().setContentMD5(oneHundredOneConstitutionsMD5);
|
.contentType("text/plain").contentMD5(oneHundredOneConstitutionsMD5)
|
||||||
sourceObject.getMetadata().getContentMetadata().setContentLength(oneHundredOneConstitutionsLength);
|
.contentLength(oneHundredOneConstitutionsLength).contentDisposition(contentDisposition).build());
|
||||||
sourceObject.getMetadata().getContentMetadata().setContentDisposition(contentDisposition);
|
|
||||||
context.getBlobStore().putBlob(containerName, sourceObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
|
@ -364,8 +364,8 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
@DataProvider(name = "delete")
|
@DataProvider(name = "delete")
|
||||||
public Object[][] createData() {
|
public Object[][] createData() {
|
||||||
return new Object[][] { { "normal" }, { "sp ace" }, { "qu?stion" }, { "unic₪de" }, { "path/foo" }, { "colon:" },
|
return new Object[][] { { "normal" }, { "sp ace" }, { "qu?stion" }, { "unic₪de" }, { "path/foo" },
|
||||||
{ "asteri*k" }, { "quote\"" }, { "{great<r}" }, { "lesst>en" }, { "p|pe" } };
|
{ "colon:" }, { "asteri*k" }, { "quote\"" }, { "{great<r}" }, { "lesst>en" }, { "p|pe" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" }, dataProvider = "delete")
|
@Test(groups = { "integration", "live" }, dataProvider = "delete")
|
||||||
|
@ -390,9 +390,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
assertEquals(Iterables.size(listing), 0, String.format(
|
assertEquals(
|
||||||
"deleting %s, we still have %s blobs left in container %s, using encoding %s", key, Iterables
|
Iterables.size(listing),
|
||||||
.size(listing), containerName, LOCAL_ENCODING));
|
0,
|
||||||
|
String.format("deleting %s, we still have %s blobs left in container %s, using encoding %s", key,
|
||||||
|
Iterables.size(listing), containerName, LOCAL_ENCODING));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
|
@ -419,14 +421,13 @@ public class BaseBlobIntegrationTest 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) throws InterruptedException,
|
public void testPutObject(String key, String type, Object content, Object realObject) throws InterruptedException,
|
||||||
IOException {
|
IOException {
|
||||||
Blob blob = context.getBlobStore().newBlob(key);
|
PayloadBlobBuilder blobBuilder = context.getBlobStore().blobBuilder(key).payload(Payloads.newPayload(content))
|
||||||
blob.setPayload(Payloads.newPayload(content));
|
.contentType(type);
|
||||||
blob.getMetadata().getContentMetadata().setContentType(type);
|
addContentMetadata(blobBuilder);
|
||||||
addContentMetadata(blob);
|
|
||||||
|
|
||||||
if (content instanceof InputStream) {
|
if (content instanceof InputStream) {
|
||||||
Payloads.calculateMD5(blob, context.utils().crypto().md5());
|
blobBuilder.calculateMD5();
|
||||||
}
|
}
|
||||||
|
Blob blob = blobBuilder.build();
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
assertNotNull(context.getBlobStore().putBlob(containerName, blob));
|
assertNotNull(context.getBlobStore().putBlob(containerName, blob));
|
||||||
|
@ -444,14 +445,15 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException {
|
public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException {
|
||||||
Blob blob = context.getBlobStore().newBlob("streaming");
|
PayloadBlobBuilder blobBuilder = context.getBlobStore().blobBuilder("streaming").payload(new StreamingPayload(new WriteTo() {
|
||||||
blob.setPayload(new StreamingPayload(new WriteTo() {
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
public void writeTo(OutputStream outstream) throws IOException {
|
||||||
outstream.write("foo".getBytes());
|
outstream.write("foo".getBytes());
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
addContentMetadata(blob);
|
addContentMetadata(blobBuilder);
|
||||||
|
|
||||||
|
Blob blob = blobBuilder.build();
|
||||||
|
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
|
@ -476,11 +478,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
checkContentLanguage(blob, "en");
|
checkContentLanguage(blob, "en");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addContentMetadata(Blob blob) {
|
private void addContentMetadata(PayloadBlobBuilder blobBuilder) {
|
||||||
blob.getMetadata().getContentMetadata().setContentType("text/csv");
|
blobBuilder.contentType("text/csv");
|
||||||
blob.getMetadata().getContentMetadata().setContentDisposition("attachment; filename=photo.jpg");
|
blobBuilder.contentDisposition("attachment; filename=photo.jpg");
|
||||||
blob.getMetadata().getContentMetadata().setContentEncoding("gzip");
|
blobBuilder.contentEncoding("gzip");
|
||||||
blob.getMetadata().getContentMetadata().setContentLanguage("en");
|
blobBuilder.contentLanguage("en");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkContentType(Blob blob, String contentType) {
|
protected void checkContentType(Blob blob, String contentType) {
|
||||||
|
@ -526,15 +528,11 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testMetadata() throws InterruptedException, IOException {
|
public void testMetadata() throws InterruptedException, IOException {
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
|
|
||||||
Blob blob = context.getBlobStore().newBlob(key);
|
|
||||||
blob.setPayload(TEST_STRING);
|
|
||||||
blob.getMetadata().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
|
||||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to
|
// NOTE all metadata in jclouds comes out as lowercase, in an effort to
|
||||||
// normalize the
|
// normalize the
|
||||||
// providers.
|
// providers.
|
||||||
blob.getMetadata().getUserMetadata().put("Adrian", "powderpuff");
|
Blob blob = context.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||||
Payloads.calculateMD5(blob, context.utils().crypto().md5());
|
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).calculateMD5().build();
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
assertNull(context.getBlobStore().blobMetadata(containerName, "powderpuff"));
|
assertNull(context.getBlobStore().blobMetadata(containerName, "powderpuff"));
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
private static final String sysHttpStreamETag = System.getProperty("jclouds.blobstore.httpstream.md5");
|
private static final String sysHttpStreamETag = System.getProperty("jclouds.blobstore.httpstream.md5");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" })
|
@Parameters({ "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" })
|
||||||
public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamETag) throws Exception {
|
public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamETag) throws Exception {
|
||||||
httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl");
|
httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl");
|
||||||
|
|
||||||
|
@ -61,10 +61,7 @@ public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
long length = connection.getContentLength();
|
long length = connection.getContentLength();
|
||||||
InputStream input = connection.getInputStream();
|
InputStream input = connection.getInputStream();
|
||||||
|
|
||||||
Blob blob = context.getBlobStore().newBlob(name);
|
Blob blob = context.getBlobStore().blobBuilder(name).payload(input).contentLength(length).contentMD5(md5).build();
|
||||||
blob.setPayload(input);
|
|
||||||
blob.getPayload().getContentMetadata().setContentLength(length);
|
|
||||||
blob.getPayload().getContentMetadata().setContentMD5(md5);
|
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().putBlob(container, blob);
|
context.getBlobStore().putBlob(container, blob);
|
||||||
|
|
|
@ -20,17 +20,16 @@
|
||||||
package org.jclouds.blobstore.integration.internal;
|
package org.jclouds.blobstore.integration.internal;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.inDirectory;
|
||||||
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults;
|
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults;
|
||||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose;
|
import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ -42,7 +41,12 @@ import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,19 +56,32 @@ import com.google.common.collect.Sets;
|
||||||
*/
|
*/
|
||||||
public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<Blob> {
|
public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<Blob> {
|
||||||
|
|
||||||
|
private static class StringToBlob implements Function<String, Blob> {
|
||||||
|
private final BlobMap map;
|
||||||
|
|
||||||
|
private StringToBlob(BlobMap map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blob apply(String arg0) {
|
||||||
|
return map.blobBuilder().payload(arg0).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testValues() throws IOException, InterruptedException {
|
public void testValues() throws IOException, InterruptedException {
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
Map<String, Blob> map = createMap(context, bucketName);
|
BlobMap map = createMap(context, bucketName);
|
||||||
|
|
||||||
putFiveStrings(map);
|
putFiveStrings(map);
|
||||||
putFiveStringsUnderPath(map);
|
putFiveStringsUnderPath(map);
|
||||||
|
|
||||||
Collection<Blob> blobs = map.values();
|
Collection<Blob> blobs = map.values();
|
||||||
assertConsistencyAwareMapSize(map, 5);
|
assertConsistencyAwareMapSize(map, 5);
|
||||||
Set<String> blobsAsString = new HashSet<String>();
|
Set<String> blobsAsString = Sets.newLinkedHashSet();
|
||||||
for (Blob blob : blobs) {
|
for (Blob blob : blobs) {
|
||||||
blobsAsString.add(getContentAsStringOrNullAndClose(blob));
|
blobsAsString.add(getContentAsStringOrNullAndClose(blob));
|
||||||
}
|
}
|
||||||
|
@ -110,7 +127,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
public void testEntrySet() throws IOException, InterruptedException {
|
public void testEntrySet() throws IOException, InterruptedException {
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
final Map<String, Blob> map = createMap(context, bucketName);
|
final BlobMap map = createMap(context, bucketName);
|
||||||
putFiveStrings(map);
|
putFiveStrings(map);
|
||||||
assertConsistencyAwareMapSize(map, 5);
|
assertConsistencyAwareMapSize(map, 5);
|
||||||
Set<Entry<String, Blob>> entries = map.entrySet();
|
Set<Entry<String, Blob>> entries = map.entrySet();
|
||||||
|
@ -145,9 +162,7 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
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 blob = context.getBlobStore().newBlob("one");
|
Blob blob = context.getBlobStore().blobBuilder("one").payload("apple").calculateMD5().build();
|
||||||
blob.setPayload("apple");
|
|
||||||
Payloads.calculateMD5(blob);
|
|
||||||
assertConsistencyAwareContainsValue(map, blob);
|
assertConsistencyAwareContainsValue(map, blob);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(bucketName);
|
returnContainer(bucketName);
|
||||||
|
@ -172,9 +187,8 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
Map<String, Blob> map = createMap(context, bucketName);
|
Map<String, Blob> map = createMap(context, bucketName);
|
||||||
Blob blob = context.getBlobStore().newBlob("one");
|
Blob blob = context.getBlobStore().blobBuilder("one").payload(Strings2.toInputStream("apple")).calculateMD5()
|
||||||
blob.setPayload(Strings2.toInputStream("apple"));
|
.build();
|
||||||
Payloads.calculateMD5(blob);
|
|
||||||
Blob old = map.put(blob.getMetadata().getName(), blob);
|
Blob old = map.put(blob.getMetadata().getName(), blob);
|
||||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||||
blob.setPayload(Strings2.toInputStream("bear"));
|
blob.setPayload(Strings2.toInputStream("bear"));
|
||||||
|
@ -191,16 +205,16 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
Map<String, Blob> map = createMap(context, bucketName);
|
Map<String, Blob> map = createMap(context, bucketName);
|
||||||
Map<String, Blob> newMap = new HashMap<String, Blob>();
|
ImmutableMap.Builder<String, Blob> newMap = ImmutableMap.<String, Blob> builder();
|
||||||
for (String key : fiveInputs.keySet()) {
|
for (String key : fiveInputs.keySet()) {
|
||||||
Blob blob = context.getBlobStore().newBlob(key);
|
newMap.put(
|
||||||
blob.setPayload(fiveInputs.get(key));
|
key,
|
||||||
blob.getPayload().getContentMetadata().setContentLength((long) fiveBytes.get(key).length);
|
context.getBlobStore().blobBuilder(key).payload(fiveInputs.get(key))
|
||||||
newMap.put(key, blob);
|
.contentLength((long) fiveBytes.get(key).length).build());
|
||||||
}
|
}
|
||||||
map.putAll(newMap);
|
map.putAll(newMap.build());
|
||||||
assertConsistencyAwareMapSize(map, 5);
|
assertConsistencyAwareMapSize(map, 5);
|
||||||
assertConsistencyAwareKeySetEquals(map, new HashSet<String>(fiveInputs.keySet()));
|
assertConsistencyAwareKeySetEquals(map, ImmutableSet.copyOf(fiveInputs.keySet()));
|
||||||
fourLeftRemovingOne(map);
|
fourLeftRemovingOne(map);
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(bucketName);
|
returnContainer(bucketName);
|
||||||
|
@ -213,23 +227,21 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
return;
|
return;
|
||||||
String bucketName = getContainerName();
|
String bucketName = getContainerName();
|
||||||
try {
|
try {
|
||||||
Map<String, Blob> map = createMap(context, bucketName);
|
BlobMap map = createMap(context, bucketName);
|
||||||
Set<String> keySet = Sets.newHashSet();
|
Builder<String> keySet = ImmutableSet.<String> builder();
|
||||||
for (int i = 0; i < maxResultsForTestListings() + 1; i++) {
|
for (int i = 0; i < maxResultsForTestListings() + 1; i++) {
|
||||||
keySet.add(i + "");
|
keySet.add(i + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Blob> newMap = new HashMap<String, Blob>();
|
Map<String, Blob> newMap = Maps.newLinkedHashMap();
|
||||||
for (String key : keySet) {
|
for (String key : keySet.build()) {
|
||||||
Blob blob = context.getBlobStore().newBlob(key);
|
newMap.put(key, map.blobBuilder().payload(key).build());
|
||||||
blob.setPayload(key);
|
|
||||||
newMap.put(key, blob);
|
|
||||||
}
|
}
|
||||||
map.putAll(newMap);
|
map.putAll(newMap);
|
||||||
newMap.clear();
|
newMap.clear();
|
||||||
|
|
||||||
assertConsistencyAwareMapSize(map, maxResultsForTestListings() + 1);
|
assertConsistencyAwareMapSize(map, maxResultsForTestListings() + 1);
|
||||||
assertConsistencyAwareKeySetEquals(map, keySet);
|
assertConsistencyAwareKeySetEquals(map, keySet.build());
|
||||||
map.clear();
|
map.clear();
|
||||||
assertConsistencyAwareMapSize(map, 0);
|
assertConsistencyAwareMapSize(map, 0);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -239,30 +251,15 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void putStringWithMD5(Map<String, Blob> map, String key, String text) throws IOException {
|
protected void putStringWithMD5(Map<String, Blob> map, String key, String text) throws IOException {
|
||||||
Blob blob = context.getBlobStore().newBlob(key);
|
map.put(key, context.getBlobStore().blobBuilder(key).payload(text).calculateMD5().build());
|
||||||
blob.setPayload(text);
|
|
||||||
Payloads.calculateMD5(blob);
|
|
||||||
map.put(key, blob);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putFiveStrings(Map<String, Blob> map) {
|
protected void putFiveStrings(BlobMap map) {
|
||||||
Map<String, Blob> newMap = new HashMap<String, Blob>();
|
map.putAll(Maps.transformValues(fiveStrings, new StringToBlob(map)));
|
||||||
for (Map.Entry<String, String> entry : fiveStrings.entrySet()) {
|
|
||||||
Blob blob = context.getBlobStore().newBlob(entry.getKey());
|
|
||||||
blob.setPayload(entry.getValue());
|
|
||||||
newMap.put(entry.getKey(), blob);
|
|
||||||
}
|
|
||||||
map.putAll(newMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putFiveStringsUnderPath(Map<String, Blob> map) {
|
protected void putFiveStringsUnderPath(BlobMap map) {
|
||||||
Map<String, Blob> newMap = new HashMap<String, Blob>();
|
map.putAll(Maps.transformValues(fiveStringsUnderPath, new StringToBlob(map)));
|
||||||
for (Map.Entry<String, String> entry : fiveStringsUnderPath.entrySet()) {
|
|
||||||
Blob blob = context.getBlobStore().newBlob(entry.getKey());
|
|
||||||
blob.setPayload(entry.getValue());
|
|
||||||
newMap.put(entry.getKey(), blob);
|
|
||||||
}
|
|
||||||
map.putAll(newMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int maxResultsForTestListings() {
|
protected int maxResultsForTestListings() {
|
||||||
|
@ -276,4 +273,20 @@ public abstract class BaseBlobMapIntegrationTest extends BaseMapIntegrationTest<
|
||||||
protected BlobMap createMap(BlobStoreContext context, String bucket, ListContainerOptions options) {
|
protected BlobMap createMap(BlobStoreContext context, String bucket, ListContainerOptions options) {
|
||||||
return context.createBlobMap(bucket, options);
|
return context.createBlobMap(bucket, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
||||||
|
BlobMap blobMap = createMap(context, containerName, inDirectory(prefix));
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
blobMap.put(i + "", blobMap.blobBuilder().payload(i + "content").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addTenObjectsUnderRoot(String containerName) throws InterruptedException {
|
||||||
|
BlobMap blobMap = createMap(context, containerName, ListContainerOptions.NONE);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
blobMap.put(i + "", blobMap.blobBuilder().payload(i + "content").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
String name = "hello";
|
String name = "hello";
|
||||||
String text = "fooooooooooooooooooooooo";
|
String text = "fooooooooooooooooooooooo";
|
||||||
|
|
||||||
Blob blob = context.getBlobStore().newBlob(name);
|
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||||
blob.setPayload(text);
|
|
||||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().putBlob(container, blob);
|
context.getBlobStore().putBlob(container, blob);
|
||||||
|
@ -62,9 +60,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
String name = "hello";
|
String name = "hello";
|
||||||
String text = "fooooooooooooooooooooooo";
|
String text = "fooooooooooooooooooooooo";
|
||||||
|
|
||||||
Blob blob = context.getBlobStore().newBlob(name);
|
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||||
blob.setPayload(text);
|
|
||||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().putBlob(container, blob);
|
context.getBlobStore().putBlob(container, blob);
|
||||||
|
@ -82,9 +78,7 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
String name = "hello";
|
String name = "hello";
|
||||||
String text = "fooooooooooooooooooooooo";
|
String text = "fooooooooooooooooooooooo";
|
||||||
|
|
||||||
Blob blob = context.getBlobStore().newBlob(name);
|
Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
|
||||||
blob.setPayload(text);
|
|
||||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
|
||||||
String container = getContainerName();
|
String container = getContainerName();
|
||||||
try {
|
try {
|
||||||
HttpRequest request = context.getSigner().signPutBlob(container, blob);
|
HttpRequest request = context.getSigner().signPutBlob(container, blob);
|
||||||
|
|
|
@ -244,17 +244,14 @@ public class BaseBlobStoreIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String addBlobToContainer(String sourceContainer, String key, String payload, String contentType) {
|
protected String addBlobToContainer(String sourceContainer, String key, String payload, String contentType) {
|
||||||
Blob sourceObject = context.getBlobStore().newBlob(key);
|
Blob sourceObject = context.getBlobStore().blobBuilder(key).payload(payload).contentType(contentType).build();
|
||||||
sourceObject.setPayload(payload);
|
|
||||||
sourceObject.getMetadata().getContentMetadata().setContentType(contentType);
|
|
||||||
return addBlobToContainer(sourceContainer, sourceObject);
|
return addBlobToContainer(sourceContainer, sourceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
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().newBlob(entry.getKey());
|
Blob sourceObject = context.getBlobStore().blobBuilder(entry.getKey()).payload(entry.getValue())
|
||||||
sourceObject.setPayload(entry.getValue());
|
.contentType("text/xml").build();
|
||||||
sourceObject.getMetadata().getContentMetadata().setContentType("text/xml");
|
|
||||||
addBlobToContainer(sourceContainer, sourceObject);
|
addBlobToContainer(sourceContainer, sourceObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,10 @@ import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
import org.jclouds.io.InputSuppliers;
|
import org.jclouds.io.InputSuppliers;
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -60,8 +61,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
try {
|
try {
|
||||||
context.getBlobStore().createContainerInLocation(null, containerName);
|
context.getBlobStore().createContainerInLocation(null, containerName);
|
||||||
|
|
||||||
Blob blob = context.getBlobStore().newBlob("hello");
|
Blob blob = context.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build();
|
||||||
blob.setPayload(TEST_STRING);
|
|
||||||
context.getBlobStore().putBlob(containerName, blob);
|
context.getBlobStore().putBlob(containerName, blob);
|
||||||
|
|
||||||
context.getBlobStore().createContainerInLocation(null, containerName);
|
context.getBlobStore().createContainerInLocation(null, containerName);
|
||||||
|
@ -74,18 +74,13 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
@Test(groups = { "integration", "live" })
|
@Test(groups = { "integration", "live" })
|
||||||
public void testWithDetails() throws InterruptedException, IOException {
|
public void testWithDetails() throws InterruptedException, IOException {
|
||||||
String key = "hello";
|
String key = "hello";
|
||||||
|
|
||||||
Blob object = context.getBlobStore().newBlob(key);
|
|
||||||
object.setPayload(TEST_STRING);
|
|
||||||
object.getMetadata().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
|
||||||
// NOTE all metadata in jclouds comes out as lowercase, in an effort to
|
|
||||||
// normalize the
|
|
||||||
// providers.
|
|
||||||
object.getMetadata().getUserMetadata().put("Adrian", "powderpuff");
|
|
||||||
Payloads.calculateMD5(object, context.utils().crypto().md5());
|
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
addBlobToContainer(containerName, object);
|
addBlobToContainer(containerName,
|
||||||
|
// NOTE all metadata in jclouds comes out as lowercase, in an effort to
|
||||||
|
// normalize the providers.
|
||||||
|
context.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff"))
|
||||||
|
.payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).calculateMD5().build());
|
||||||
validateContent(containerName, key);
|
validateContent(containerName, key);
|
||||||
|
|
||||||
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName,
|
PageSet<? extends StorageMetadata> container = context.getBlobStore().list(containerName,
|
||||||
|
@ -329,9 +324,8 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
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 = context.getBlobStore().newBlob(letter + "");
|
context.getBlobStore().putBlob(containerName,
|
||||||
blob.setPayload(letter + "content");
|
context.getBlobStore().blobBuilder(letter + "").payload(letter + "content").build());
|
||||||
context.getBlobStore().putBlob(containerName, blob);
|
|
||||||
}
|
}
|
||||||
assertContainerSize(containerName, 26);
|
assertContainerSize(containerName, 26);
|
||||||
|
|
||||||
|
@ -351,17 +345,15 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
|
||||||
|
|
||||||
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 = context.getBlobStore().newBlob(i + "");
|
context.getBlobStore().putBlob(containerName,
|
||||||
blob.setPayload(i + "content");
|
context.getBlobStore().blobBuilder(i + "").payload(i + "content").build());
|
||||||
context.getBlobStore().putBlob(containerName, blob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
Blob blob = context.getBlobStore().newBlob(prefix + "/" + i);
|
context.getBlobStore().putBlob(containerName,
|
||||||
blob.setPayload(i + "content");
|
context.getBlobStore().blobBuilder(prefix + "/" + i).payload(i + "content").build());
|
||||||
context.getBlobStore().putBlob(containerName, blob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,11 +27,10 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
||||||
assertConsistencyAwareMapSize(map, 5);
|
assertConsistencyAwareMapSize(map, 5);
|
||||||
Collection<InputStream> values = map.values();
|
Collection<InputStream> values = map.values();
|
||||||
assertEquals(values.size(), 5);
|
assertEquals(values.size(), 5);
|
||||||
Set<String> valuesAsString = new HashSet<String>();
|
Set<String> valuesAsString = Sets.newLinkedHashSet();
|
||||||
for (InputStream stream : values) {
|
for (InputStream stream : values) {
|
||||||
valuesAsString.add(Strings2.toStringAndClose(stream));
|
valuesAsString.add(Strings2.toStringAndClose(stream));
|
||||||
}
|
}
|
||||||
|
@ -77,7 +76,7 @@ public abstract class BaseInputStreamMapIntegrationTest extends BaseMapIntegrati
|
||||||
String containerName = getContainerName();
|
String containerName = getContainerName();
|
||||||
try {
|
try {
|
||||||
InputStreamMap map = createMap(context, containerName);
|
InputStreamMap map = createMap(context, containerName);
|
||||||
Set<String> keySet = Sets.newHashSet();
|
Set<String> keySet = Sets.newLinkedHashSet();
|
||||||
for (int i = 0; i < maxResultsForTestListings() + 1; i++) {
|
for (int i = 0; i < maxResultsForTestListings() + 1; i++) {
|
||||||
keySet.add(i + "");
|
keySet.add(i + "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,14 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ListableMap;
|
import org.jclouds.blobstore.ListableMap;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -50,6 +49,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
@ -82,7 +82,7 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass(groups = { "integration", "live" })
|
@BeforeClass(groups = { "integration", "live" })
|
||||||
@Parameters( { "basedir" })
|
@Parameters({ "basedir" })
|
||||||
protected void setUpTempDir(@Optional String basedir) throws InterruptedException, ExecutionException,
|
protected void setUpTempDir(@Optional String basedir) throws InterruptedException, ExecutionException,
|
||||||
FileNotFoundException, IOException, TimeoutException {
|
FileNotFoundException, IOException, TimeoutException {
|
||||||
if (basedir == null) {
|
if (basedir == null) {
|
||||||
|
@ -138,17 +138,15 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
||||||
|
|
||||||
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
protected void addTenObjectsUnderPrefix(String containerName, String prefix) throws InterruptedException {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
Blob blob = context.getBlobStore().newBlob(prefix + "/" + i);
|
context.getBlobStore().putBlob(containerName,
|
||||||
blob.setPayload(i + "content");
|
context.getBlobStore().blobBuilder(prefix + "/" + i).payload(i + "content").build());
|
||||||
context.getBlobStore().putBlob(containerName, blob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addTenObjectsUnderRoot(String containerName) throws InterruptedException {
|
protected void addTenObjectsUnderRoot(String containerName) throws InterruptedException {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
Blob blob = context.getBlobStore().newBlob(i + "");
|
context.getBlobStore().putBlob(containerName,
|
||||||
blob.setPayload(i + "content");
|
context.getBlobStore().blobBuilder(i + "").payload(i + "content").build());
|
||||||
context.getBlobStore().putBlob(containerName, blob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,15 +163,28 @@ public abstract class BaseMapIntegrationTest<V> extends BaseBlobStoreIntegration
|
||||||
context.getBlobStore().createDirectory(containerName, directory);
|
context.getBlobStore().createDirectory(containerName, directory);
|
||||||
addTenObjectsUnderRoot(containerName);
|
addTenObjectsUnderRoot(containerName);
|
||||||
assertEquals(rootMap.size(), 10);
|
assertEquals(rootMap.size(), 10);
|
||||||
|
assertEquals(ImmutableSortedSet.copyOf(rootMap.keySet()),
|
||||||
|
ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
|
||||||
assertEquals(rootRecursiveMap.size(), 10);
|
assertEquals(rootRecursiveMap.size(), 10);
|
||||||
|
assertEquals(ImmutableSortedSet.copyOf(rootRecursiveMap.keySet()),
|
||||||
|
ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
|
||||||
assertEquals(inDirectoryMap.size(), 0);
|
assertEquals(inDirectoryMap.size(), 0);
|
||||||
assertEquals(inDirectoryRecursiveMap.size(), 0);
|
assertEquals(inDirectoryRecursiveMap.size(), 0);
|
||||||
|
|
||||||
addTenObjectsUnderPrefix(containerName, directory);
|
addTenObjectsUnderPrefix(containerName, directory);
|
||||||
assertEquals(rootMap.size(), 10);
|
assertEquals(rootMap.size(), 10);
|
||||||
|
assertEquals(ImmutableSortedSet.copyOf(rootMap.keySet()),
|
||||||
|
ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
|
||||||
assertEquals(rootRecursiveMap.size(), 20);
|
assertEquals(rootRecursiveMap.size(), 20);
|
||||||
|
assertEquals(ImmutableSortedSet.copyOf(rootRecursiveMap.keySet()), ImmutableSet.of("0", "1", "2", "3", "4",
|
||||||
|
"5", "6", "7", "8", "9", "apps/0", "apps/1", "apps/2", "apps/3", "apps/4", "apps/5", "apps/6", "apps/7",
|
||||||
|
"apps/8", "apps/9"));
|
||||||
assertEquals(inDirectoryMap.size(), 10);
|
assertEquals(inDirectoryMap.size(), 10);
|
||||||
|
assertEquals(ImmutableSortedSet.copyOf(inDirectoryMap.keySet()),
|
||||||
|
ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
|
||||||
assertEquals(inDirectoryRecursiveMap.size(), 10);
|
assertEquals(inDirectoryRecursiveMap.size(), 10);
|
||||||
|
assertEquals(ImmutableSortedSet.copyOf(inDirectoryRecursiveMap.keySet()),
|
||||||
|
ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"));
|
||||||
|
|
||||||
context.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
context.getBlobStore().createDirectory(containerName, directory + "/" + directory);
|
||||||
assertEquals(rootMap.size(), 10);
|
assertEquals(rootMap.size(), 10);
|
||||||
|
|
|
@ -25,10 +25,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextFactory;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.internal.ConcatenateContainerLists;
|
|
||||||
import org.jclouds.blobstore.strategy.internal.ListContainerAndRecurseThroughFolders;
|
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -48,9 +45,7 @@ public class BiggerThanPageSizeTest {
|
||||||
public void test() throws IOException {
|
public void test() throws IOException {
|
||||||
blobstore.createContainerInLocation(null, "goodies");
|
blobstore.createContainerInLocation(null, "goodies");
|
||||||
for (int i = 0; i < 1001; i++) {
|
for (int i = 0; i < 1001; i++) {
|
||||||
Blob blob = blobstore.newBlob(i + "");
|
blobstore.putBlob("goodies", blobstore.blobBuilder(i + "").payload(i + "").build());
|
||||||
blob.setPayload(i + "");
|
|
||||||
blobstore.putBlob("goodies", blob);
|
|
||||||
}
|
}
|
||||||
assertEquals(blobstore.countBlobs("goodies"), 1001);
|
assertEquals(blobstore.countBlobs("goodies"), 1001);
|
||||||
blobstore.clearContainer("goodies");
|
blobstore.clearContainer("goodies");
|
||||||
|
@ -60,9 +55,7 @@ public class BiggerThanPageSizeTest {
|
||||||
public void testStrategies() throws IOException {
|
public void testStrategies() throws IOException {
|
||||||
blobstore.createContainerInLocation(null, "poo");
|
blobstore.createContainerInLocation(null, "poo");
|
||||||
for (int i = 0; i < 1001; i++) {
|
for (int i = 0; i < 1001; i++) {
|
||||||
Blob blob = blobstore.newBlob(i + "");
|
blobstore.putBlob("poo", blobstore.blobBuilder(i + "").payload(i + "").build());
|
||||||
blob.setPayload(i + "");
|
|
||||||
blobstore.putBlob("poo", blob);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListContainerAndRecurseThroughFolders lister = new ListContainerAndRecurseThroughFolders(
|
ListContainerAndRecurseThroughFolders lister = new ListContainerAndRecurseThroughFolders(
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class MutableResourceMetadataImpl<T extends Enum<T>> implements MutableRe
|
||||||
private Map<String, String> userMetadata;
|
private Map<String, String> userMetadata;
|
||||||
|
|
||||||
public MutableResourceMetadataImpl() {
|
public MutableResourceMetadataImpl() {
|
||||||
userMetadata = Maps.newHashMap();
|
userMetadata = Maps.newLinkedHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableResourceMetadataImpl(ResourceMetadata<T> from) {
|
public MutableResourceMetadataImpl(ResourceMetadata<T> from) {
|
||||||
|
|
|
@ -109,14 +109,16 @@ public class Payloads {
|
||||||
public static Payload calculateMD5(Payload payload, MessageDigest md5) throws IOException {
|
public static Payload calculateMD5(Payload payload, MessageDigest md5) throws IOException {
|
||||||
checkNotNull(payload, "payload");
|
checkNotNull(payload, "payload");
|
||||||
if (!payload.isRepeatable()) {
|
if (!payload.isRepeatable()) {
|
||||||
String oldContentType = payload.getContentMetadata().getContentType();
|
MutableContentMetadata oldContentMetadata = payload.getContentMetadata();
|
||||||
Payload oldPayload = payload;
|
Payload oldPayload = payload;
|
||||||
try {
|
try {
|
||||||
payload = newByteArrayPayload(toByteArray(payload));
|
payload = newByteArrayPayload(toByteArray(payload));
|
||||||
} finally {
|
} finally {
|
||||||
oldPayload.release();
|
oldPayload.release();
|
||||||
}
|
}
|
||||||
payload.getContentMetadata().setContentType(oldContentType);
|
oldContentMetadata.setContentLength(payload.getContentMetadata().getContentLength());
|
||||||
|
oldContentMetadata.setContentMD5(payload.getContentMetadata().getContentMD5());
|
||||||
|
payload.setContentMetadata(oldContentMetadata);
|
||||||
}
|
}
|
||||||
payload.getContentMetadata().setContentMD5(CryptoStreams.digest(payload, md5));
|
payload.getContentMetadata().setContentMD5(CryptoStreams.digest(payload, md5));
|
||||||
return payload;
|
return payload;
|
||||||
|
|
|
@ -35,7 +35,7 @@ import com.google.common.base.Function;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class AzureBlobToBlob implements Function<AzureBlob, Blob> {
|
public class AzureBlobToBlob implements Function<AzureBlob, Blob> {
|
||||||
private final Blob.Factory blobFactory;
|
private final Factory blobFactory;
|
||||||
private final BlobPropertiesToBlobMetadata blobPr2BlobMd;
|
private final BlobPropertiesToBlobMetadata blobPr2BlobMd;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
Loading…
Reference in New Issue