You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/10/05 22:18:22 UTC
[1/3] git commit: JCLOUDS-40 Remove AsyncBlobStore
Repository: jclouds
Updated Branches:
refs/heads/master 56a2a8bf4 -> cacc986dc
JCLOUDS-40 Remove AsyncBlobStore
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/a4e3c1a2
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/a4e3c1a2
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/a4e3c1a2
Branch: refs/heads/master
Commit: a4e3c1a2f8305d94143c67e26372db3bf24c6206
Parents: 56a2a8b
Author: Adrian Cole <ad...@gmail.com>
Authored: Sun Oct 5 11:40:48 2014 -0700
Committer: Adrian Cole <ad...@gmail.com>
Committed: Sun Oct 5 13:17:54 2014 -0700
----------------------------------------------------------------------
.../src/main/clojure/org/jclouds/blobstore2.clj | 11 +-
.../org/jclouds/blobstore/AsyncBlobStore.java | 173 -----------
.../java/org/jclouds/blobstore/BlobStore.java | 4 -
.../org/jclouds/blobstore/BlobStoreContext.java | 10 -
.../internal/BlobStoreContextImpl.java | 12 +-
.../internal/SubmissionAsyncBlobStore.java | 293 -------------------
.../internal/BaseBlobIntegrationTest.java | 42 +--
7 files changed, 20 insertions(+), 525 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/main/clojure/org/jclouds/blobstore2.clj
----------------------------------------------------------------------
diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore2.clj b/blobstore/src/main/clojure/org/jclouds/blobstore2.clj
index 98d51cb..bb06e5f 100644
--- a/blobstore/src/main/clojure/org/jclouds/blobstore2.clj
+++ b/blobstore/src/main/clojure/org/jclouds/blobstore2.clj
@@ -44,7 +44,7 @@ See http://code.google.com/p/jclouds for details."
java.util.Properties
[org.jclouds ContextBuilder]
[org.jclouds.blobstore
- AsyncBlobStore domain.BlobBuilder BlobStore BlobStoreContext
+ domain.BlobBuilder BlobStore BlobStoreContext
domain.BlobMetadata domain.StorageMetadata domain.PageSet
domain.Blob domain.internal.BlobBuilderImpl options.PutOptions
options.PutOptions$Builder
@@ -86,8 +86,6 @@ See http://code.google.com/p/jclouds for details."
(defn blobstore
"Create a logged in context.
-Options for communication style
- :sync and :async.
Options can also be specified for extension modules
:log4j :enterprise :ning :apachehc :bouncycastle :joda :gae"
[^String provider ^String provider-identity ^String provider-credential
@@ -102,9 +100,7 @@ Options can also be specified for extension modules
(overrides (reduce #(do (.put ^Properties %1 (name (first %2)) (second %2)) %1)
(Properties.) (dissoc opts :extensions)))
(buildView BlobStoreContext))]
- (if (some #(= :async %) options)
- (.getAsyncBlobStore context)
- (.getBlobStore context)))))
+ (.getBlobStore context))))
(defn blobstore-context
"Returns a blobstore context from a blobstore."
@@ -117,8 +113,7 @@ Options can also be specified for extension modules
(defn blobstore?
[object]
- (or (instance? BlobStore object)
- (instance? AsyncBlobStore object)))
+ (instance? BlobStore object))
(defn blobstore-context?
[object]
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java
----------------------------------------------------------------------
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java
deleted file mode 100644
index a121455..0000000
--- a/blobstore/src/main/java/org/jclouds/blobstore/AsyncBlobStore.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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;
-
-import java.util.Set;
-
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.domain.BlobBuilder;
-import org.jclouds.blobstore.domain.BlobMetadata;
-import org.jclouds.blobstore.domain.PageSet;
-import org.jclouds.blobstore.domain.StorageMetadata;
-import org.jclouds.blobstore.internal.SubmissionAsyncBlobStore;
-import org.jclouds.blobstore.options.CreateContainerOptions;
-import org.jclouds.blobstore.options.GetOptions;
-import org.jclouds.blobstore.options.ListContainerOptions;
-import org.jclouds.blobstore.options.PutOptions;
-import org.jclouds.domain.Location;
-import org.jclouds.javax.annotation.Nullable;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.inject.ImplementedBy;
-
-/**
- * Provides hooks needed to run a blob store asynchronously
- *
- * @see BlobStore
- * @deprecated will be removed in jclouds 1.7, as async interfaces are no longer
- * supported. Please use {@link org.jclouds.blobstore.BlobStore}
- */
-@Deprecated
-@ImplementedBy(SubmissionAsyncBlobStore.class)
-public interface AsyncBlobStore {
- /**
- * @see BlobStore#getContext
- */
- BlobStoreContext getContext();
-
- /**
- * @see BlobStore#blobBuilder
- */
- BlobBuilder blobBuilder(String name);
-
- /**
- * @see BlobStore#listAssignableLocations
- */
- ListenableFuture<Set<? extends Location>> listAssignableLocations();
-
- /**
- * @see BlobStore#list
- */
- ListenableFuture<PageSet<? extends StorageMetadata>> list();
-
- /**
- * @see BlobStore#containerExists
- */
- ListenableFuture<Boolean> containerExists(String container);
-
- /**
- * @see BlobStore#createContainerInLocation(Location, String)
- */
- ListenableFuture<Boolean> createContainerInLocation(@Nullable Location location, String container);
-
- /**
- * @see BlobStore#createContainerInLocation(Location,String,CreateContainerOptions)
- */
- ListenableFuture<Boolean> createContainerInLocation(@Nullable Location location, String container,
- CreateContainerOptions options);
-
- /**
- * @see BlobStore#list(String)
- */
- ListenableFuture<PageSet<? extends StorageMetadata>> list(String container);
-
- /**
- * @see BlobStore#list(String, ListContainerOptions)
- */
- ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options);
-
- /**
- * @see BlobStore#clearContainer(String)
- */
- ListenableFuture<Void> clearContainer(String container);
-
- /**
- * @see BlobStore#clearContainer(String, ListContainerOptions)
- */
- ListenableFuture<Void> clearContainer(String container, ListContainerOptions options);
-
- /**
- * @see BlobStore#deleteContainer
- */
- ListenableFuture<Void> deleteContainer(String container);
-
- /**
- * @see BlobStore#deleteContainerIfEmpty
- */
- ListenableFuture<Boolean> deleteContainerIfEmpty(String container);
-
- /**
- * @see BlobStore#directoryExists
- */
- ListenableFuture<Boolean> directoryExists(String container, String directory);
-
- /**
- * @see BlobStore#createDirectory
- */
- ListenableFuture<Void> createDirectory(String container, String directory);
-
- /**
- * @see BlobStore#deleteDirectory
- */
- ListenableFuture<Void> deleteDirectory(String containerName, String name);
-
- /**
- * @see BlobStore#blobExists
- */
- ListenableFuture<Boolean> blobExists(String container, String name);
-
- /**
- * @see BlobStore#putBlob(String,Blob)
- */
- ListenableFuture<String> putBlob(String container, Blob blob);
-
- /**
- * @see BlobStore#putBlob(String,Blob,PutOptions)
- */
- ListenableFuture<String> putBlob(String container, Blob blob, PutOptions options);
-
- /**
- * @see BlobStore#blobMetadata
- */
- ListenableFuture<BlobMetadata> blobMetadata(String container, String key);
-
- /**
- * @see BlobStore#getBlob(String, String)
- */
- ListenableFuture<Blob> getBlob(String container, String key);
-
- /**
- * @see BlobStore#getBlob(String, String, GetOptions)
- */
- ListenableFuture<Blob> getBlob(String container, String key, GetOptions options);
-
- /**
- * @see BlobStore#removeBlob
- */
- ListenableFuture<Void> removeBlob(String container, String key);
-
- /**
- * @see BlobStore#countBlobs(String)
- */
- ListenableFuture<Long> countBlobs(String container);
-
- /**
- * @see BlobStore#countBlobs(String,ListContainerOptions)
- */
- ListenableFuture<Long> countBlobs(String container, ListContainerOptions options);
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java
----------------------------------------------------------------------
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java
index 88db39a..5dde0cd 100644
--- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java
+++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStore.java
@@ -32,10 +32,6 @@ import org.jclouds.javax.annotation.Nullable;
/**
* Synchronous access to a BlobStore such as Amazon S3
- *
- * @see AsyncBlobStore
- *
- * @see BlobStoreContextFactory
*/
public interface BlobStore {
/**
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java
----------------------------------------------------------------------
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java
index 8d66d10..1a569dd 100644
--- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java
+++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContext.java
@@ -39,16 +39,6 @@ public interface BlobStoreContext extends Closeable, View {
BlobRequestSigner getSigner();
/**
- * @return a portable asynchronous interface for the BlobStore, which returns
- * {@code Future}s for each call.
- * @deprecated will be removed in jclouds 1.7, as async interfaces are no
- * longer supported. Please use
- * {@link #getBlobStore()}
- */
- @Deprecated
- AsyncBlobStore getAsyncBlobStore();
-
- /**
* @return a portable interface for the BlobStore.
*/
BlobStore getBlobStore();
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java
----------------------------------------------------------------------
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java
index 6d0ea01..6aea926 100644
--- a/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java
+++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/BlobStoreContextImpl.java
@@ -22,7 +22,6 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.Context;
-import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
@@ -36,7 +35,6 @@ import com.google.common.reflect.TypeToken;
@Singleton
public class BlobStoreContextImpl extends BaseView implements BlobStoreContext {
- private final AsyncBlobStore ablobStore;
private final BlobStore blobStore;
private final ConsistencyModel consistencyModel;
private final Utils utils;
@@ -44,12 +42,9 @@ public class BlobStoreContextImpl extends BaseView implements BlobStoreContext {
@Inject
public BlobStoreContextImpl(@Provider Context backend, @Provider TypeToken<? extends Context> backendType,
- Utils utils, ConsistencyModel consistencyModel,
- AsyncBlobStore ablobStore, BlobStore blobStore,
- BlobRequestSigner blobRequestSigner) {
+ Utils utils, ConsistencyModel consistencyModel, BlobStore blobStore, BlobRequestSigner blobRequestSigner) {
super(backend, backendType);
this.consistencyModel = checkNotNull(consistencyModel, "consistencyModel");
- this.ablobStore = checkNotNull(ablobStore, "ablobStore");
this.blobStore = checkNotNull(blobStore, "blobStore");
this.utils = checkNotNull(utils, "utils");
this.blobRequestSigner = checkNotNull(blobRequestSigner, "blobRequestSigner");
@@ -66,11 +61,6 @@ public class BlobStoreContextImpl extends BaseView implements BlobStoreContext {
}
@Override
- public AsyncBlobStore getAsyncBlobStore() {
- return ablobStore;
- }
-
- @Override
public Utils utils() {
return utils;
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/main/java/org/jclouds/blobstore/internal/SubmissionAsyncBlobStore.java
----------------------------------------------------------------------
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/SubmissionAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/SubmissionAsyncBlobStore.java
deleted file mode 100644
index b141008..0000000
--- a/blobstore/src/main/java/org/jclouds/blobstore/internal/SubmissionAsyncBlobStore.java
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.Constants.PROPERTY_USER_THREADS;
-
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jclouds.blobstore.AsyncBlobStore;
-import org.jclouds.blobstore.BlobStore;
-import org.jclouds.blobstore.BlobStoreContext;
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.domain.BlobBuilder;
-import org.jclouds.blobstore.domain.BlobMetadata;
-import org.jclouds.blobstore.domain.PageSet;
-import org.jclouds.blobstore.domain.StorageMetadata;
-import org.jclouds.blobstore.options.CreateContainerOptions;
-import org.jclouds.blobstore.options.GetOptions;
-import org.jclouds.blobstore.options.ListContainerOptions;
-import org.jclouds.blobstore.options.PutOptions;
-import org.jclouds.domain.Location;
-
-import com.google.common.collect.ForwardingObject;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-
-/**
- * Adapter that allows you to reuse an existing {@link BlobStore} to implement
- * the deprecated {@link AsyncBlobStore} interface.
- *
- * @deprecated will be removed in jclouds 2.0, as async interfaces are no longer
- * supported. Please use {@link BlobStore}
- */
-@Deprecated
-public class SubmissionAsyncBlobStore extends ForwardingObject implements AsyncBlobStore {
- private final BlobStore blobstore;
- private final ListeningExecutorService executor;
-
- @Inject
- public SubmissionAsyncBlobStore(BlobStore blobstore, @Named(PROPERTY_USER_THREADS) ListeningExecutorService executor) {
- this.blobstore = checkNotNull(blobstore, "blobstore");
- this.executor = checkNotNull(executor, "executor");
- }
-
- @Override
- protected BlobStore delegate() {
- return blobstore;
- }
-
- @Override
- public BlobStoreContext getContext() {
- return delegate().getContext();
- }
-
- @Override
- public BlobBuilder blobBuilder(String name) {
- return delegate().blobBuilder(name);
- }
-
- @Override
- public ListenableFuture<Set<? extends Location>> listAssignableLocations() {
- return executor.submit(new Callable<Set<? extends Location>>() {
- public Set<? extends Location> call() {
- return delegate().listAssignableLocations();
- }
- });
- }
-
- @Override
- public ListenableFuture<PageSet<? extends StorageMetadata>> list() {
- return executor.submit(new Callable<PageSet<? extends StorageMetadata>>() {
- public PageSet<? extends StorageMetadata> call() {
- return delegate().list();
- }
- });
- }
-
- @Override
- public ListenableFuture<Boolean> containerExists(final String container) {
- return executor.submit(new Callable<Boolean>() {
- public Boolean call() {
- return delegate().containerExists(container);
- }
- });
- }
-
- @Override
- public ListenableFuture<Boolean> createContainerInLocation(final Location location, final String container) {
- return executor.submit(new Callable<Boolean>() {
- public Boolean call() {
- return delegate().createContainerInLocation(location, container);
- }
- });
- }
-
- @Override
- public ListenableFuture<Boolean> createContainerInLocation(final Location location, final String container,
- final CreateContainerOptions options) {
- return executor.submit(new Callable<Boolean>() {
- public Boolean call() {
- return delegate().createContainerInLocation(location, container, options);
- }
- });
- }
-
- @Override
- public ListenableFuture<PageSet<? extends StorageMetadata>> list(final String container) {
- return executor.submit(new Callable<PageSet<? extends StorageMetadata>>() {
- public PageSet<? extends StorageMetadata> call() {
- return delegate().list(container);
- }
- });
- }
-
- @Override
- public ListenableFuture<PageSet<? extends StorageMetadata>> list(final String container,
- final ListContainerOptions options) {
- return executor.submit(new Callable<PageSet<? extends StorageMetadata>>() {
- public PageSet<? extends StorageMetadata> call() {
- return delegate().list(container, options);
- }
- });
- }
-
- @Override
- public ListenableFuture<Void> clearContainer(final String container) {
- return executor.submit(new Callable<Void>() {
- public Void call() {
- delegate().clearContainer(container);
- return null;
- }
- });
- }
-
- @Override
- public ListenableFuture<Void> clearContainer(final String container, final ListContainerOptions options) {
- return executor.submit(new Callable<Void>() {
- public Void call() {
- delegate().clearContainer(container, options);
- return null;
- }
- });
- }
-
- @Override
- public ListenableFuture<Void> deleteContainer(final String container) {
- return executor.submit(new Callable<Void>() {
- public Void call() {
- delegate().deleteContainer(container);
- return null;
- }
- });
- }
-
- @Override
- public ListenableFuture<Boolean> deleteContainerIfEmpty(final String container) {
- return executor.submit(new Callable<Boolean>() {
- public Boolean call() {
- return delegate().deleteContainerIfEmpty(container);
- }
- });
- }
-
- @Override
- public ListenableFuture<Boolean> directoryExists(final String container, final String directory) {
- return executor.submit(new Callable<Boolean>() {
- public Boolean call() {
- return delegate().directoryExists(container, directory);
- }
- });
- }
-
- @Override
- public ListenableFuture<Void> createDirectory(final String container, final String directory) {
- return executor.submit(new Callable<Void>() {
- public Void call() {
- delegate().createDirectory(container, directory);
- return null;
- }
- });
- }
-
- @Override
- public ListenableFuture<Void> deleteDirectory(final String containerName, final String name) {
- return executor.submit(new Callable<Void>() {
- public Void call() {
- delegate().deleteDirectory(containerName, name);
- return null;
- }
- });
- }
-
- @Override
- public ListenableFuture<Boolean> blobExists(final String container, final String name) {
- return executor.submit(new Callable<Boolean>() {
- public Boolean call() {
- return delegate().blobExists(container, name);
- }
- });
- }
-
- @Override
- public ListenableFuture<String> putBlob(final String container, final Blob blob) {
- return executor.submit(new Callable<String>() {
- public String call() {
- return delegate().putBlob(container, blob);
- }
- });
- }
-
- @Override
- public ListenableFuture<String> putBlob(final String container, final Blob blob, final PutOptions options) {
- return executor.submit(new Callable<String>() {
- public String call() {
- return delegate().putBlob(container, blob, options);
- }
- });
- }
-
- @Override
- public ListenableFuture<BlobMetadata> blobMetadata(final String container, final String key) {
- return executor.submit(new Callable<BlobMetadata>() {
- public BlobMetadata call() {
- return delegate().blobMetadata(container, key);
- }
- });
- }
-
- @Override
- public ListenableFuture<Blob> getBlob(final String container, final String key) {
- return executor.submit(new Callable<Blob>() {
- public Blob call() {
- return delegate().getBlob(container, key);
- }
- });
- }
-
- @Override
- public ListenableFuture<Blob> getBlob(final String container, final String key, final GetOptions options) {
- return executor.submit(new Callable<Blob>() {
- public Blob call() {
- return delegate().getBlob(container, key, options);
- }
- });
- }
-
- @Override
- public ListenableFuture<Void> removeBlob(final String container, final String key) {
- return executor.submit(new Callable<Void>() {
- public Void call() {
- delegate().removeBlob(container, key);
- return null;
- }
- });
- }
-
- @Override
- public ListenableFuture<Long> countBlobs(final String container) {
- return executor.submit(new Callable<Long>() {
- public Long call() {
- return delegate().countBlobs(container);
- }
- });
- }
-
- @Override
- public ListenableFuture<Long> countBlobs(final String container, final ListContainerOptions options) {
- return executor.submit(new Callable<Long>() {
- public Long call() {
- return delegate().countBlobs(container, options);
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a4e3c1a2/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
----------------------------------------------------------------------
diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
index eb55098..dca61a1 100644
--- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
+++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java
@@ -24,6 +24,7 @@ import static org.jclouds.blobstore.options.GetOptions.Builder.ifModifiedSince;
import static org.jclouds.blobstore.options.GetOptions.Builder.ifUnmodifiedSince;
import static org.jclouds.blobstore.options.GetOptions.Builder.range;
import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
+import static org.jclouds.io.ByteStreams2.hashAndClose;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
@@ -55,7 +56,6 @@ import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.crypto.Crypto;
import org.jclouds.encryption.internal.JCECrypto;
import org.jclouds.http.HttpResponseException;
-import org.jclouds.io.ByteStreams2;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.ByteSourcePayload;
@@ -67,7 +67,6 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.google.common.base.Charsets;
-import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
@@ -76,7 +75,6 @@ import com.google.common.collect.Maps;
import com.google.common.hash.HashCode;
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
-import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Uninterruptibles;
@@ -93,10 +91,6 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
return oneHundredOneConstitutions;
}
- public static long getOneHundredOneConstitutionsLength() throws IOException {
- return oneHundredOneConstitutions.size();
- }
-
/**
* Attempt to capture the issue detailed in
* http://groups.google.com/group/jclouds/browse_thread/thread/4a7c8d58530b287f
@@ -108,7 +102,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
createTestInput(32 * 1024).copyTo(Files.asByteSink(payloadFile));
final Payload testPayload = Payloads.newFilePayload(payloadFile);
- final HashCode md5 = ByteStreams2.hashAndClose(testPayload.openStream(), md5());
+ final HashCode md5 = hashAndClose(testPayload.openStream(), md5());
testPayload.getContentMetadata().setContentType("image/png");
final AtomicInteger blobCount = new AtomicInteger();
@@ -127,7 +121,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
assertConsistencyAwareBlobExists(container, name);
blob = view.getBlobStore().getBlob(container, name);
- assertEquals(ByteStreams2.hashAndClose(blob.getPayload().openStream(), md5()), md5,
+ assertEquals(hashAndClose(blob.getPayload().openStream(), md5()), md5,
String.format("md5 didn't match on %s/%s", container, name));
view.getBlobStore().removeBlob(container, name);
@@ -158,23 +152,19 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
uploadByteSource(container, name, expectedContentDisposition, supplier);
Map<Integer, ListenableFuture<?>> responses = Maps.newHashMap();
for (int i = 0; i < 10; i++) {
-
- responses.put(i, Futures.transform(view.getAsyncBlobStore().getBlob(container, name),
- new Function<Blob, Void>() {
-
- @Override
- public Void apply(Blob from) {
- try {
- validateMetadata(from.getMetadata(), container, name);
- assertEquals(ByteStreams2.hashAndClose(from.getPayload().openStream(), md5()), supplier.hash(md5()));
- checkContentDisposition(from, expectedContentDisposition);
- } catch (IOException e) {
- Throwables.propagate(e);
- }
- return null;
- }
-
- }, this.exec));
+ responses.put(i, this.exec.submit(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ try {
+ Blob blob = view.getBlobStore().getBlob(container, name);
+ validateMetadata(blob.getMetadata(), container, name);
+ assertEquals(hashAndClose(blob.getPayload().openStream(), md5()), supplier.hash(md5()));
+ checkContentDisposition(blob, expectedContentDisposition);
+ } catch (IOException e) {
+ Throwables.propagate(e);
+ }
+ return null;
+ }
+ }));
}
Map<Integer, Exception> exceptions = awaitCompletion(responses, exec, 30000l, Logger.CONSOLE,
"get constitution");
[3/3] git commit: JCLOUDS-40 Remove AsyncBlobStore references from s3
api
Posted by ad...@apache.org.
JCLOUDS-40 Remove AsyncBlobStore references from s3 api
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/cacc986d
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/cacc986d
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/cacc986d
Branch: refs/heads/master
Commit: cacc986dc4b69be5bb732fcd096ddafd5f9c57c2
Parents: a22a725
Author: Adrian Cole <ad...@gmail.com>
Authored: Sun Oct 5 11:41:48 2014 -0700
Committer: Adrian Cole <ad...@gmail.com>
Committed: Sun Oct 5 13:18:12 2014 -0700
----------------------------------------------------------------------
.../s3/blobstore/internal/S3BlobStoreContextImpl.java | 8 ++------
.../aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java | 8 ++------
2 files changed, 4 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/cacc986d/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java
index a2aaf9a..220606c 100644
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java
+++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/internal/S3BlobStoreContextImpl.java
@@ -20,7 +20,6 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.Context;
-import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.attr.ConsistencyModel;
@@ -37,11 +36,8 @@ public class S3BlobStoreContextImpl extends BlobStoreContextImpl implements S3Bl
@Inject
public S3BlobStoreContextImpl(@Provider Context backend, @Provider TypeToken<? extends Context> backendType,
- Utils utils, ConsistencyModel consistencyModel,
- AsyncBlobStore ablobStore, BlobStore blobStore,
- BlobRequestSigner blobRequestSigner) {
- super(backend, backendType, utils, consistencyModel, ablobStore,
- blobStore, blobRequestSigner);
+ Utils utils, ConsistencyModel consistencyModel, BlobStore blobStore, BlobRequestSigner blobRequestSigner) {
+ super(backend, backendType, utils, consistencyModel, blobStore, blobRequestSigner);
}
@Override
http://git-wip-us.apache.org/repos/asf/jclouds/blob/cacc986d/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java
----------------------------------------------------------------------
diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java
index 9455f01..83d66b0 100644
--- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java
+++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/internal/AWSS3BlobStoreContextImpl.java
@@ -22,7 +22,6 @@ import javax.inject.Singleton;
import org.jclouds.Context;
import org.jclouds.aws.s3.blobstore.AWSS3BlobStore;
import org.jclouds.aws.s3.blobstore.AWSS3BlobStoreContext;
-import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.attr.ConsistencyModel;
@@ -37,11 +36,8 @@ public class AWSS3BlobStoreContextImpl extends S3BlobStoreContextImpl implements
@Inject
public AWSS3BlobStoreContextImpl(@Provider Context backend, @Provider TypeToken<? extends Context> backendType,
- Utils utils, ConsistencyModel consistencyModel,
- AsyncBlobStore ablobStore, BlobStore blobStore,
- BlobRequestSigner blobRequestSigner) {
- super(backend, backendType, utils, consistencyModel, ablobStore,
- blobStore, blobRequestSigner);
+ Utils utils, ConsistencyModel consistencyModel, BlobStore blobStore, BlobRequestSigner blobRequestSigner) {
+ super(backend, backendType, utils, consistencyModel, blobStore, blobRequestSigner);
}
@Override
[2/3] git commit: JCLOUDS-40 Remove AsyncBlobStore references from
filesystem api
Posted by ad...@apache.org.
JCLOUDS-40 Remove AsyncBlobStore references from filesystem api
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/a22a7252
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/a22a7252
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/a22a7252
Branch: refs/heads/master
Commit: a22a72529332a2d8620c21c0aaa7ae39a435b2fb
Parents: a4e3c1a
Author: Adrian Cole <ad...@gmail.com>
Authored: Sun Oct 5 11:41:36 2014 -0700
Committer: Adrian Cole <ad...@gmail.com>
Committed: Sun Oct 5 13:18:02 2014 -0700
----------------------------------------------------------------------
.../util/internal/FileSystemBlobUtilsImpl.java | 2 +-
.../FilesystemAsyncBlobStoreTest.java | 859 -------------------
.../filesystem/FilesystemBlobStoreTest.java | 817 ++++++++++++++++++
.../src/test/resources/logging.properties | 2 -
4 files changed, 818 insertions(+), 862 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a22a7252/apis/filesystem/src/main/java/org/jclouds/filesystem/util/internal/FileSystemBlobUtilsImpl.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/internal/FileSystemBlobUtilsImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/internal/FileSystemBlobUtilsImpl.java
index 3dfcd31..2dbd2ad 100644
--- a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/internal/FileSystemBlobUtilsImpl.java
+++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/internal/FileSystemBlobUtilsImpl.java
@@ -30,7 +30,7 @@ import com.google.inject.Inject;
/**
* Implements the {@link BlobUtils} interfaced and act as a bridge to
- * {@link LocalStorageStrategy} when used inside {@link AsyncBlobStore}
+ * {@link LocalStorageStrategy} when used inside {@link BlobStore}
*/
public class FileSystemBlobUtilsImpl implements BlobUtils {
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a22a7252/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java
deleted file mode 100644
index 3129241..0000000
--- a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java
+++ /dev/null
@@ -1,859 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.filesystem;
-
-import static com.google.common.io.BaseEncoding.base16;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNotSame;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import org.jclouds.ContextBuilder;
-import org.jclouds.blobstore.BlobRequestSigner;
-import org.jclouds.blobstore.BlobStore;
-import org.jclouds.blobstore.BlobStoreContext;
-import org.jclouds.blobstore.ContainerNotFoundException;
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.domain.BlobMetadata;
-import org.jclouds.blobstore.domain.MutableBlobMetadata;
-import org.jclouds.blobstore.domain.PageSet;
-import org.jclouds.blobstore.domain.StorageMetadata;
-import org.jclouds.blobstore.domain.StorageType;
-import org.jclouds.blobstore.options.GetOptions;
-import org.jclouds.blobstore.options.ListContainerOptions;
-import org.jclouds.filesystem.reference.FilesystemConstants;
-import org.jclouds.filesystem.util.Utils;
-import org.jclouds.filesystem.utils.TestUtils;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.io.ByteStreams2;
-import org.jclouds.io.Payload;
-import org.jclouds.io.payloads.PhantomPayload;
-import org.jclouds.io.payloads.StringPayload;
-import org.jclouds.util.Closeables2;
-import org.jclouds.util.Strings2;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.Sets;
-import com.google.common.io.ByteSource;
-import com.google.common.io.Files;
-import com.google.inject.CreationException;
-
-/**
- * Test class for {@link FilesystemAsyncBlobStore} class
- */
-@Test(groups = "unit", testName = "filesystem.FilesystemAsyncBlobStoreTest", singleThreaded = true)
-public class FilesystemAsyncBlobStoreTest {
-
- 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 LOGGING_CONFIG_KEY = "java.util.logging.config.file";
- private static final String LOGGING_CONFIG_VALUE = "src/main/resources/logging.properties";
-
- private static final String PROVIDER = "filesystem";
-
- static {
- System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
- }
-
- private BlobStoreContext context = null;
- private BlobStore blobStore = null;
-
- @BeforeMethod
- protected void setUp() throws Exception {
- // create context for filesystem container
- Properties prop = new Properties();
- prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
- context = ContextBuilder.newBuilder(PROVIDER).overrides(prop).build(BlobStoreContext.class);
- // create a container in the default location
- blobStore = context.getBlobStore();
- new File(TestUtils.TARGET_BASE_DIR).mkdir();
- TestUtils.createResources();
- }
-
- @AfterMethod
- protected void tearDown() throws IOException {
- context.close();
- Utils.deleteRecursively(new File(TestUtils.TARGET_BASE_DIR));
- }
-
- /**
- * Checks if context parameters are managed in the correct way
- */
- public void testParameters() {
- // no base directory declared in properties
- try {
- Properties props = new Properties();
- context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build(BlobStoreContext.class);
- fail("No error if base directory is not specified");
- } catch (CreationException e) {
- }
-
- // no base directory declared in properties
- try {
- Properties props = new Properties();
- props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null);
- context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build(BlobStoreContext.class);
- fail("No error if base directory is null in the option");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * Test of list method of the root context
- */
- public void testList_Root() throws IOException {
- PageSet<? extends StorageMetadata> containersRetrieved;
- Set<String> containersCreated = Sets.newHashSet();
-
- // Testing list with no containers
- containersRetrieved = blobStore.list();
- assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
-
- // Testing list with some containers
- String[] containerNames = {"34343", "aaaa", "bbbbb"};
- containersCreated = Sets.newHashSet();
- for (String containerName : containerNames) {
- blobStore.createContainerInLocation(null, containerName);
- containersCreated.add(containerName);
- }
-
- containersRetrieved = blobStore.list();
- assertEquals(containersCreated.size(), containersRetrieved.size(), "Different numbers of container");
-
- for (StorageMetadata data : containersRetrieved) {
- String containerName = data.getName();
- if (!containersCreated.remove(containerName)) {
- fail("Container list contains unexpected value [" + containerName + "]");
- }
- }
- assertTrue(containersCreated.isEmpty(), "List operation doesn't return all values.");
-
- for (String containerName : containerNames) {
- // delete all creaded containers
- blobStore.deleteContainer(containerName);
- }
- containersRetrieved = blobStore.list();
- assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
- }
-
- /**
- * Test of list method, of class FilesystemAsyncBlobStore.
- */
- public void testList_NoOptionSingleContainer() throws IOException {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- // Testing list for an empty container
- checkForContainerContent(CONTAINER_NAME, null);
-
- // creates blobs in first container
- Set<String> blobsExpected = TestUtils.createBlobsInContainer(CONTAINER_NAME, "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);
- }
-
- public void testList_NotExistingContainer() {
- // Testing list for a not existing container
- try {
- blobStore.list(CONTAINER_NAME);
- fail("Found a not existing container");
- } catch (ContainerNotFoundException e) {
- // ok if arriver here
- }
- }
-
- /**
- * Test of list method, of class FilesystemAsyncBlobStore.
- */
- public void testList_NoOptionDoubleContainer() throws IOException {
- final String CONTAINER_NAME2 = "container2";
-
- // create first container
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- // checks for empty container
- checkForContainerContent(CONTAINER_NAME, null);
-
- // create second container
- blobStore.createContainerInLocation(null, CONTAINER_NAME2);
- // checks for empty
- checkForContainerContent(CONTAINER_NAME2, null);
-
- // creates blobs in first container
-
- Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(CONTAINER_NAME, "bbb"
- + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
- TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
- + File.separator + "wert.kpg");
-
- // creates blobs in second container
- blobStore.createContainerInLocation(null, CONTAINER_NAME2);
- Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(CONTAINER_NAME2, "asd"
- + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
- TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
- + File.separator + "wert.kpg");
-
- // test blobs in first container
- checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
- // test blobs in second container
- checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
- }
-
- public void testList_Subdirectory() throws IOException {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- // Testing list for an empty container
- checkForContainerContent(CONTAINER_NAME, null);
-
- // creates blobs in first container
- Set<String> blobsExpected = TestUtils.createBlobsInContainer(CONTAINER_NAME, "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
- blobsExpected.remove("bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg");
- blobsExpected.remove("4rrr.jpg");
-
- checkForContainerContent(CONTAINER_NAME, "rrr", blobsExpected);
- }
-
- /**
- * TODO Should throws an exception?
- */
- public void testClearContainer_NotExistingContainer() {
- blobStore.clearContainer(CONTAINER_NAME);
- }
-
- /**
- * Integration test, because clearContainer is not redefined in
- * {@link FilesystemAsyncBlobStore} class
- */
- public void testClearContainer_NoOptions() throws IOException {
- final String CONTAINER_NAME2 = "containerToClear";
-
- // create containers
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- blobStore.createContainerInLocation(null, CONTAINER_NAME2);
-
- // creates blobs in first container
- Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(CONTAINER_NAME, "bbb"
- + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
- TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
- + File.separator + "wert.kpg");
-
- // creates blobs in second container
- blobStore.createContainerInLocation(null, CONTAINER_NAME2);
- Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(CONTAINER_NAME2, "asd"
- + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
- TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
- + File.separator + "wert.kpg");
-
- // test blobs in containers
- checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
- checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
-
- // delete blobs in first container
- blobStore.clearContainer(CONTAINER_NAME);
- checkForContainerContent(CONTAINER_NAME, null);
- checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
- // delete blobs in second container
- blobStore.clearContainer(CONTAINER_NAME2);
- checkForContainerContent(CONTAINER_NAME2, null);
- }
-
- /**
- * Integration test, because countBlobs is not redefined in
- * {@link FilesystemAsyncBlobStore} class
- */
- public void testCountBlobs_NotExistingContainer() {
- blobStore.countBlobs(PROVIDER);
- }
-
- /**
- * Integration test, because countBlobs is not redefined in
- * {@link FilesystemAsyncBlobStore} class
- */
- public void testCountBlobs_NoOptionsEmptyContainer() {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- blobStore.countBlobs(PROVIDER);
- }
-
- /**
- * Integration test, because countBlobs is not redefined in
- * {@link FilesystemAsyncBlobStore} class
- */
- public void testCountBlobs_NoOptions() {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- blobStore.countBlobs(PROVIDER);
- }
-
- public void testRemoveBlob_SimpleBlobKey() throws IOException {
- final String BLOB_KEY = TestUtils.createRandomBlobKey(null, ".txt");
- boolean result;
-
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
-
- // checks that blob doesn't exists
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
- assertFalse(result, "Blob exists");
-
- // create the blob
- TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
- assertTrue(result, "Blob exists");
-
- // remove it
- blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
- assertFalse(result, "Blob still exists");
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
- }
-
- public void testRemoveBlob_TwoSimpleBlobKeys() throws IOException {
- final String BLOB_KEY1 = TestUtils.createRandomBlobKey(null, null);
- final String BLOB_KEY2 = TestUtils.createRandomBlobKey(null, null);
- boolean result;
-
- // create the container and checks that blob doesn't exists
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
- assertFalse(result, "Blob1 exists");
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertFalse(result, "Blob2 exists");
-
- // create the blob
- TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
- assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
-
- // remove first blob
- blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
- assertFalse(result, "Blob1 still exists");
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertTrue(result, "Blob2 doesn't exist");
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
- // remove second blob
- blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertFalse(result, "Blob2 still exists");
- 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
- public void testRemoveBlob_ComplexBlobKey() throws IOException {
- final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
- boolean result;
-
- // checks that blob doesn't exists
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
- assertFalse(result, "Blob exists");
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
-
- // create the blob
- TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
- assertTrue(result, "Blob doesn't exist");
-
- // remove it
- blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
- assertFalse(result, "Blob still exists");
- // file removed
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
- // also the entire directory structure was removed
- TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
- }
-
- /**
- * Test of removeBlob method, with two blobs with a complex path as key and
- * when first blob is removed, not all of its key's path is removed, because
- * it is shared with the second blob's key
- */
- @Test
- public void testRemoveBlob_TwoComplexBlobKeys() throws IOException {
- final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
- final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null);
- boolean result;
-
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
-
- // checks that blob doesn't exist
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
- assertFalse(result, "Blob1 exists");
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertFalse(result, "Blob2 exists");
-
- // create the blobs
- TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
- assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
-
- // remove first blob
- blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
- assertFalse(result, "Blob still exists");
- // first file deleted, not the second
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
- // only partial directory structure was removed, because it shares a path
- // with the second blob created
- TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb/cc/dd", false);
- TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb", true);
- // remove second blob
- blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
- result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
- assertFalse(result, "Blob still exists");
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
- // now all the directory structure is empty
- TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
- }
-
- /**
- * Test of containerExists method, of class FilesystemAsyncBlobStore.
- */
- public void testContainerExists() throws IOException {
- boolean result;
-
- result = blobStore.containerExists(CONTAINER_NAME);
- assertFalse(result, "Container exists");
-
- // create container
- TestUtils.createContainerAsDirectory(CONTAINER_NAME);
-
- result = blobStore.containerExists(CONTAINER_NAME);
- assertTrue(result, "Container doesn't exist");
- }
-
- /**
- * Test of createContainerInLocation method, of class
- * FilesystemAsyncBlobStore.
- */
- public void testCreateContainerInLocation() throws IOException {
- final String CONTAINER_NAME2 = "funambol-test-2";
- final String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
-
- boolean result;
-
- result = blobStore.containerExists(CONTAINER_NAME);
- assertFalse(result, "Container exists");
- result = blobStore.createContainerInLocation(null, CONTAINER_NAME);
- assertTrue(result, "Container not created");
- result = blobStore.containerExists(CONTAINER_NAME);
- assertTrue(result, "Container doesn't exist");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
-
- result = blobStore.containerExists(CONTAINER_NAME2);
- assertFalse(result, "Container exists");
- result = blobStore.createContainerInLocation(null, CONTAINER_NAME2);
- assertTrue(result, "Container not created");
- result = blobStore.containerExists(CONTAINER_NAME2);
- assertTrue(result, "Container doesn't exist");
- TestUtils.directoryExists(TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2, true);
- }
-
- /**
- * Test of putBlob method, of class FilesystemAsyncBlobStore. with a simple
- * filename - no path in the filename, eg filename.jpg
- */
- public void testPutBlobSimpleName() {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
- }
-
- /**
- * Test of putBlob method with a complex key, with path in the filename, eg
- * picture/filename.jpg
- */
- public void testPutBlobComplexName1() {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("picture/putBlob-", ".jpg"));
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("video/putBlob-", ".jpg"));
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("video/putBlob-", ".jpg"));
- }
-
- /**
- * Test of putBlob method with a complex key, with path in the filename, eg
- * picture/filename.jpg
- */
- public void testPutBlobComplexName2() {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("aa/bb/cc/dd/ee/putBlob-", ".jpg"));
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("aa/bb/cc/dd/ee/putBlob-", ".jpg"));
- putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
- }
-
- /**
- * Test of blobExists method, of class FilesystemAsyncBlobStore.
- */
- public void testBlobExists() throws IOException {
- boolean result;
- String blobKey;
-
- // when location doesn't exists
- blobKey = TestUtils.createRandomBlobKey();
- try {
- blobStore.blobExists(CONTAINER_NAME, blobKey);
- fail();
- } catch (ContainerNotFoundException cnfe) {
- // expected
- }
-
- // when location exists
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- result = blobStore.blobExists(CONTAINER_NAME, blobKey);
- assertFalse(result, "Blob exists");
-
- // create blob
- TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload());
- result = blobStore.blobExists(CONTAINER_NAME, blobKey);
- assertTrue(result, "Blob doesn't exist");
-
- // complex path test
- blobKey = TestUtils.createRandomBlobKey("ss/asdas/", "");
- result = blobStore.blobExists(CONTAINER_NAME, blobKey);
- assertFalse(result, "Blob exists");
- TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload());
- result = blobStore.blobExists(CONTAINER_NAME, blobKey);
- assertTrue(result, "Blob doesn't exist");
- }
-
- public void testGetBlob_NotExistingContainer() {
- try {
- blobStore.getBlob(CONTAINER_NAME, TestUtils.createRandomBlobKey(), null);
- fail("Retrieve must fail, container does not exist.");
- } catch (ContainerNotFoundException e) {
- // correct if arrive here
- }
- }
-
- /**
- * Test of getBlob method, of class FilesystemAsyncBlobStore.
- */
- public void testGetBlob() throws IOException {
- String blobKey = TestUtils.createRandomBlobKey();
- GetOptions options = null;
- Blob resultBlob;
-
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
-
- resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
- assertNull(resultBlob, "Blob exists");
-
- // create blob
- TestUtils.createBlobsInContainer(CONTAINER_NAME, blobKey);
-
- resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
-
- assertNotNull(resultBlob, "Blob exists");
- // checks file content
- ByteSource expectedFile = Files.asByteSource(new File(TARGET_CONTAINER_NAME, blobKey));
- assertEquals(expectedFile.read(), ByteStreams2.toByteArrayAndClose(resultBlob.getPayload().openStream()),
- "Blob payload differs from file content");
- // metadata are verified in the test for blobMetadata, so no need to
- // perform a complete test here
- assertNotNull(resultBlob.getMetadata(), "Metadata null");
- MutableBlobMetadata metadata = resultBlob.getMetadata();
- assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
- }
-
- public void testBlobMetadata_withDefaultMetadata() throws IOException {
- String BLOB_KEY = TestUtils.createRandomBlobKey(null, null);
- // create the blob
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- Blob blob = blobStore.blobBuilder(BLOB_KEY)
- .payload(TestUtils.getImageForBlobPayload())
- .build();
- blobStore.putBlob(CONTAINER_NAME, blob);
-
- BlobMetadata metadata = blobStore.blobMetadata(CONTAINER_NAME, BLOB_KEY);
- assertNotNull(metadata, "Metadata null");
-
- assertEquals(metadata.getName(), BLOB_KEY, "Wrong blob name");
- assertEquals(metadata.getType(), StorageType.BLOB, "Wrong blob type");
- assertEquals(metadata.getContentMetadata().getContentType(), "application/unknown", "Wrong blob content-type");
- assertEquals(base16().lowerCase().encode(metadata.getContentMetadata().getContentMD5()), metadata.getETag(),
- "Wrong blob MD5");
- assertEquals(metadata.getLocation(), null, "Wrong blob location");
- assertEquals(metadata.getProviderId(), null, "Wrong blob provider id");
- assertEquals(metadata.getUri(), null, "Wrong blob URI");
- assertNotNull(metadata.getUserMetadata(), "No blob UserMetadata");
- assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
- // metadata.getLastModified()
- File file = new File(TARGET_CONTAINER_NAME, BLOB_KEY);
- assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(file.length()), "Wrong blob size");
- }
-
- public void testDeleteContainer_NotExistingContainer() {
- blobStore.deleteContainer(CONTAINER_NAME);
- }
-
- public void testDeleteContainer_EmptyContanier() {
- boolean result;
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
-
- result = blobStore.containerExists(CONTAINER_NAME);
- assertTrue(result, "Container doesn't exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
-
- // delete container
- blobStore.deleteContainer(CONTAINER_NAME);
- result = blobStore.containerExists(CONTAINER_NAME);
- assertFalse(result, "Container still exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
- }
-
- public void testDeleteContainer() throws IOException {
- boolean result;
- String CONTAINER_NAME2 = "container-to-delete";
- String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- blobStore.createContainerInLocation(null, CONTAINER_NAME2);
-
- result = blobStore.containerExists(CONTAINER_NAME);
- assertTrue(result, "Container [" + CONTAINER_NAME + "] doesn't exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
- result = blobStore.containerExists(CONTAINER_NAME2);
- assertTrue(result, "Container [" + CONTAINER_NAME2 + "] doesn't exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
-
- // create blobs inside container
- TestUtils.createBlobsInContainer(CONTAINER_NAME, TestUtils.createRandomBlobKey("testutils-", null),
- TestUtils.createRandomBlobKey("testutils-", null),
- TestUtils.createRandomBlobKey("ab123s" + File.separator + "testutils-", null));
- TestUtils.createBlobsInContainer(CONTAINER_NAME, TestUtils.createRandomBlobKey("testutils-", null),
- TestUtils.createRandomBlobKey("testutils-", null),
- TestUtils.createRandomBlobKey("asda123s" + File.separator + "testutils-", null),
- TestUtils.createRandomBlobKey("123-_3s" + File.separator + "testutils-", null));
-
- // delete first container
- blobStore.deleteContainer(CONTAINER_NAME);
- result = blobStore.containerExists(CONTAINER_NAME);
- assertFalse(result, "Container [" + CONTAINER_NAME + "] still exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
- result = blobStore.containerExists(CONTAINER_NAME2);
- assertTrue(result, "Container [" + CONTAINER_NAME2 + "] still exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
- // delete second container
- blobStore.deleteContainer(CONTAINER_NAME2);
- result = blobStore.containerExists(CONTAINER_NAME2);
- assertFalse(result, "Container [" + CONTAINER_NAME2 + "] still exists");
- TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false);
- }
-
- @Test
- public void testInvalidContainerName() {
- String containerName = "file" + File.separator + "system";
- try {
- blobStore.createContainerInLocation(null, containerName);
- fail("Wrong container name not recognized");
- } catch (IllegalArgumentException e) {
- }
- try {
- blobStore.containerExists(containerName);
- fail("Wrong container name not recognized");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testRanges() throws IOException {
- blobStore.createContainerInLocation(null, CONTAINER_NAME);
- String input = "abcdefgh";
- Payload payload;
- Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(input)).build();
- blobStore.putBlob(CONTAINER_NAME, blob);
-
- GetOptions getOptionsRangeStartAt = new GetOptions();
- getOptionsRangeStartAt.startAt(1);
- Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
- payload = blobRangeStartAt.getPayload();
- try {
- assertEquals(input.substring(1), Strings2.toStringAndClose(payload.openStream()));
- } finally {
- Closeables2.closeQuietly(payload);
- }
-
- GetOptions getOptionsRangeTail = new GetOptions();
- getOptionsRangeTail.tail(3);
- Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
- payload = blobRangeTail.getPayload();
- try {
- assertEquals(input.substring(5), Strings2.toStringAndClose(payload.openStream()));
- } finally {
- Closeables2.closeQuietly(payload);
- }
-
- GetOptions getOptionsFragment = new GetOptions();
- getOptionsFragment.range(4, 6);
- Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
- payload = blobFragment.getPayload();
- try {
- assertEquals(input.substring(4, 7), Strings2.toStringAndClose(payload.openStream()));
- } finally {
- Closeables2.closeQuietly(payload);
- }
- }
-
- /** Test that BlobRequestSigner creates expected URIs. */
- public void testBlobRequestSigner() throws Exception {
- String containerName = "container";
- String blobName = "blob";
- URI endPoint = new URI("http", "localhost",
- String.format("/transient/%s/%s", containerName, blobName),
- /*fragment=*/ null);
- BlobRequestSigner signer = context.getSigner();
- HttpRequest request;
- HttpRequest expected;
-
- request = signer.signGetBlob(containerName, blobName);
- expected = HttpRequest.builder()
- .method("GET")
- .endpoint(endPoint)
- .headers(request.getHeaders())
- .build();
- assertEquals(expected, request);
-
- request = signer.signRemoveBlob(containerName, blobName);
- expected = HttpRequest.builder()
- .method("DELETE")
- .endpoint(endPoint)
- .headers(request.getHeaders())
- .build();
- assertEquals(expected, request);
-
- Blob blob = blobStore.blobBuilder(blobName).forSigning().build();
- request = signer.signPutBlob(containerName, blob);
- expected = HttpRequest.builder()
- .method("PUT")
- .endpoint(endPoint)
- .headers(request.getHeaders())
- .payload(new PhantomPayload())
- .build();
- assertEquals(expected, request);
- }
-
- // public void testInvalidBlobKey() {
- // try {
- // blobStore.newBlob(File.separator + "testwrongblobkey");
- // fail("Wrong blob key not recognized");
- // } catch (IllegalArgumentException e) {}
- //
- // try {
- // blobStore.newBlob("testwrongblobkey" + File.separator);
- // fail("Wrong blob key not recognized");
- // } catch (IllegalArgumentException e) {}
- // }
-
- // ---------------------------------------------------------- Private Methods
-
- /**
- * Creates a {@link Blob} object filled with data from a file
- *
- * @param keyName
- * @param fileContent
- * @return
- */
- private Blob createBlob(String keyName, File filePayload) {
- return blobStore.blobBuilder(keyName).payload(filePayload).build();
- }
-
- /**
- * Tests if container contains only the expected blobs
- *
- * @param containerName
- * @param expectedBlobKeys
- */
- private void checkForContainerContent(final String containerName, Set<String> expectedBlobKeys) {
- checkForContainerContent(containerName, null, expectedBlobKeys);
- }
-
- private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
- ListContainerOptions options = ListContainerOptions.Builder.recursive();
- if (null != inDirectory && !"".equals(inDirectory))
- options.inDirectory(inDirectory);
-
- PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
- for (Iterator<? extends StorageMetadata> it = blobsRetrieved.iterator(); it.hasNext();) {
- // TODO: FluentIterable
- if (it.next().getType() != StorageType.BLOB) {
- it.remove();
- }
- }
-
- // nothing expected
- if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) {
- assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the container [" + containerName + "]");
- return;
- }
-
- // copies values
- Set<String> expectedBlobKeysCopy = Sets.newHashSet();
- for (String value : expectedBlobKeys) {
- expectedBlobKeysCopy.add(value);
- }
- assertEquals(blobsRetrieved.size(), expectedBlobKeysCopy.size(),
- "Wrong blob number retrieved in the container [" + containerName + "]");
- for (StorageMetadata data : blobsRetrieved) {
- String blobName = data.getName();
- if (!expectedBlobKeysCopy.remove(blobName)) {
- fail("List for container [" + containerName + "] contains unexpected value [" + blobName + "]");
- }
- }
- assertTrue(expectedBlobKeysCopy.isEmpty(), "List operation for container [" + containerName
- + "] doesn't return all values.");
- }
-
- /**
- * Create a blob with putBlob method
- */
- private void putBlobAndCheckIt(String blobKey) {
- Blob blob;
-
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false);
-
- // create the blob
- blob = createBlob(blobKey, TestUtils.getImageForBlobPayload());
- String eTag = blobStore.putBlob(CONTAINER_NAME, blob);
- assertNotNull(eTag, "putBlob result null");
- assertNotSame(eTag, "", "putBlob result empty");
-
- // checks if the blob exists
- TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, true);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a22a7252/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemBlobStoreTest.java
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemBlobStoreTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemBlobStoreTest.java
new file mode 100644
index 0000000..ad2bc92
--- /dev/null
+++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemBlobStoreTest.java
@@ -0,0 +1,817 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.filesystem;
+
+import static com.google.common.io.BaseEncoding.base16;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import org.jclouds.ContextBuilder;
+import org.jclouds.blobstore.BlobRequestSigner;
+import org.jclouds.blobstore.BlobStore;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.ContainerNotFoundException;
+import org.jclouds.blobstore.domain.Blob;
+import org.jclouds.blobstore.domain.BlobMetadata;
+import org.jclouds.blobstore.domain.MutableBlobMetadata;
+import org.jclouds.blobstore.domain.PageSet;
+import org.jclouds.blobstore.domain.StorageMetadata;
+import org.jclouds.blobstore.domain.StorageType;
+import org.jclouds.blobstore.options.GetOptions;
+import org.jclouds.blobstore.options.ListContainerOptions;
+import org.jclouds.filesystem.reference.FilesystemConstants;
+import org.jclouds.filesystem.util.Utils;
+import org.jclouds.filesystem.utils.TestUtils;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.io.ByteStreams2;
+import org.jclouds.io.Payload;
+import org.jclouds.io.payloads.PhantomPayload;
+import org.jclouds.io.payloads.StringPayload;
+import org.jclouds.util.Closeables2;
+import org.jclouds.util.Strings2;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Sets;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Files;
+import com.google.inject.CreationException;
+
+@Test(groups = "unit", testName = "FilesystemBlobStoreTest", singleThreaded = true)
+public class FilesystemBlobStoreTest {
+
+ 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 LOGGING_CONFIG_KEY = "java.util.logging.config.file";
+ private static final String LOGGING_CONFIG_VALUE = "src/main/resources/logging.properties";
+
+ private static final String PROVIDER = "filesystem";
+
+ static {
+ System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE);
+ }
+
+ private BlobStoreContext context = null;
+ private BlobStore blobStore = null;
+
+ @BeforeMethod
+ protected void setUp() throws Exception {
+ // create context for filesystem container
+ Properties prop = new Properties();
+ prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
+ context = ContextBuilder.newBuilder(PROVIDER).overrides(prop).build(BlobStoreContext.class);
+ // create a container in the default location
+ blobStore = context.getBlobStore();
+ new File(TestUtils.TARGET_BASE_DIR).mkdir();
+ TestUtils.createResources();
+ }
+
+ @AfterMethod
+ protected void tearDown() throws IOException {
+ context.close();
+ Utils.deleteRecursively(new File(TestUtils.TARGET_BASE_DIR));
+ }
+
+ /**
+ * Checks if context parameters are managed in the correct way
+ */
+ public void testParameters() {
+ // no base directory declared in properties
+ try {
+ Properties props = new Properties();
+ context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build(BlobStoreContext.class);
+ fail("No error if base directory is not specified");
+ } catch (CreationException e) {
+ }
+
+ // no base directory declared in properties
+ try {
+ Properties props = new Properties();
+ props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, null);
+ context = ContextBuilder.newBuilder(PROVIDER).overrides(props).build(BlobStoreContext.class);
+ fail("No error if base directory is null in the option");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ /**
+ * Test of list method of the root context
+ */
+ public void testList_Root() throws IOException {
+ PageSet<? extends StorageMetadata> containersRetrieved;
+ Set<String> containersCreated = Sets.newHashSet();
+
+ // Testing list with no containers
+ containersRetrieved = blobStore.list();
+ assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
+
+ // Testing list with some containers
+ String[] containerNames = {"34343", "aaaa", "bbbbb"};
+ containersCreated = Sets.newHashSet();
+ for (String containerName : containerNames) {
+ blobStore.createContainerInLocation(null, containerName);
+ containersCreated.add(containerName);
+ }
+
+ containersRetrieved = blobStore.list();
+ assertEquals(containersCreated.size(), containersRetrieved.size(), "Different numbers of container");
+
+ for (StorageMetadata data : containersRetrieved) {
+ String containerName = data.getName();
+ if (!containersCreated.remove(containerName)) {
+ fail("Container list contains unexpected value [" + containerName + "]");
+ }
+ }
+ assertTrue(containersCreated.isEmpty(), "List operation doesn't return all values.");
+
+ for (String containerName : containerNames) {
+ // delete all creaded containers
+ blobStore.deleteContainer(containerName);
+ }
+ containersRetrieved = blobStore.list();
+ assertTrue(containersRetrieved.isEmpty(), "List operation returns a not empty set of container");
+ }
+
+ public void testList_NoOptionSingleContainer() throws IOException {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ // Testing list for an empty container
+ checkForContainerContent(CONTAINER_NAME, null);
+
+ // creates blobs in first container
+ Set<String> blobsExpected = TestUtils.createBlobsInContainer(CONTAINER_NAME, "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);
+ }
+
+ public void testList_NotExistingContainer() {
+ // Testing list for a not existing container
+ try {
+ blobStore.list(CONTAINER_NAME);
+ fail("Found a not existing container");
+ } catch (ContainerNotFoundException e) {
+ // ok if arriver here
+ }
+ }
+
+ public void testList_NoOptionDoubleContainer() throws IOException {
+ final String CONTAINER_NAME2 = "container2";
+
+ // create first container
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ // checks for empty container
+ checkForContainerContent(CONTAINER_NAME, null);
+
+ // create second container
+ blobStore.createContainerInLocation(null, CONTAINER_NAME2);
+ // checks for empty
+ checkForContainerContent(CONTAINER_NAME2, null);
+
+ // creates blobs in first container
+
+ Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(CONTAINER_NAME, "bbb"
+ + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
+ TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
+ + File.separator + "wert.kpg");
+
+ // creates blobs in second container
+ blobStore.createContainerInLocation(null, CONTAINER_NAME2);
+ Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(CONTAINER_NAME2, "asd"
+ + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
+ TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
+ + File.separator + "wert.kpg");
+
+ // test blobs in first container
+ checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
+ // test blobs in second container
+ checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
+ }
+
+ public void testList_Subdirectory() throws IOException {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ // Testing list for an empty container
+ checkForContainerContent(CONTAINER_NAME, null);
+
+ // creates blobs in first container
+ Set<String> blobsExpected = TestUtils.createBlobsInContainer(CONTAINER_NAME, "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
+ blobsExpected.remove("bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg");
+ blobsExpected.remove("4rrr.jpg");
+
+ checkForContainerContent(CONTAINER_NAME, "rrr", blobsExpected);
+ }
+
+ /**
+ * TODO Should throws an exception?
+ */
+ public void testClearContainer_NotExistingContainer() {
+ blobStore.clearContainer(CONTAINER_NAME);
+ }
+
+ public void testClearContainer_NoOptions() throws IOException {
+ final String CONTAINER_NAME2 = "containerToClear";
+
+ // create containers
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ blobStore.createContainerInLocation(null, CONTAINER_NAME2);
+
+ // creates blobs in first container
+ Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer(CONTAINER_NAME, "bbb"
+ + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
+ TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
+ + File.separator + "wert.kpg");
+
+ // creates blobs in second container
+ blobStore.createContainerInLocation(null, CONTAINER_NAME2);
+ Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer(CONTAINER_NAME2, "asd"
+ + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg",
+ TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc"
+ + File.separator + "wert.kpg");
+
+ // test blobs in containers
+ checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1);
+ checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
+
+ // delete blobs in first container
+ blobStore.clearContainer(CONTAINER_NAME);
+ checkForContainerContent(CONTAINER_NAME, null);
+ checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2);
+ // delete blobs in second container
+ blobStore.clearContainer(CONTAINER_NAME2);
+ checkForContainerContent(CONTAINER_NAME2, null);
+ }
+
+ public void testCountBlobs_NotExistingContainer() {
+ blobStore.countBlobs(PROVIDER);
+ }
+
+ public void testCountBlobs_NoOptionsEmptyContainer() {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ blobStore.countBlobs(PROVIDER);
+ }
+
+ public void testCountBlobs_NoOptions() {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ blobStore.countBlobs(PROVIDER);
+ }
+
+ public void testRemoveBlob_SimpleBlobKey() throws IOException {
+ final String BLOB_KEY = TestUtils.createRandomBlobKey(null, ".txt");
+ boolean result;
+
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+
+ // checks that blob doesn't exists
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
+ assertFalse(result, "Blob exists");
+
+ // create the blob
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
+ assertTrue(result, "Blob exists");
+
+ // remove it
+ blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
+ assertFalse(result, "Blob still exists");
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
+ }
+
+ public void testRemoveBlob_TwoSimpleBlobKeys() throws IOException {
+ final String BLOB_KEY1 = TestUtils.createRandomBlobKey(null, null);
+ final String BLOB_KEY2 = TestUtils.createRandomBlobKey(null, null);
+ boolean result;
+
+ // create the container and checks that blob doesn't exists
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
+ assertFalse(result, "Blob1 exists");
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertFalse(result, "Blob2 exists");
+
+ // create the blob
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
+ assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
+
+ // remove first blob
+ blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
+ assertFalse(result, "Blob1 still exists");
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertTrue(result, "Blob2 doesn't exist");
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
+ // remove second blob
+ blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertFalse(result, "Blob2 still exists");
+ 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
+ public void testRemoveBlob_ComplexBlobKey() throws IOException {
+ final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
+ boolean result;
+
+ // checks that blob doesn't exists
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
+ assertFalse(result, "Blob exists");
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
+
+ // create the blob
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
+ assertTrue(result, "Blob doesn't exist");
+
+ // remove it
+ blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY);
+ assertFalse(result, "Blob still exists");
+ // file removed
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false);
+ // also the entire directory structure was removed
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
+ }
+
+ /**
+ * Test of removeBlob method, with two blobs with a complex path as key and
+ * when first blob is removed, not all of its key's path is removed, because
+ * it is shared with the second blob's key
+ */
+ @Test
+ public void testRemoveBlob_TwoComplexBlobKeys() throws IOException {
+ final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null);
+ final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null);
+ boolean result;
+
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+
+ // checks that blob doesn't exist
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
+ assertFalse(result, "Blob1 exists");
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertFalse(result, "Blob2 exists");
+
+ // create the blobs
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
+ assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist");
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist");
+
+ // remove first blob
+ blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1);
+ assertFalse(result, "Blob still exists");
+ // first file deleted, not the second
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false);
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true);
+ // only partial directory structure was removed, because it shares a path
+ // with the second blob created
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb/cc/dd", false);
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb", true);
+ // remove second blob
+ blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2);
+ result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2);
+ assertFalse(result, "Blob still exists");
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false);
+ // now all the directory structure is empty
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false);
+ }
+
+ public void testContainerExists() throws IOException {
+ boolean result;
+
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertFalse(result, "Container exists");
+
+ // create container
+ TestUtils.createContainerAsDirectory(CONTAINER_NAME);
+
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertTrue(result, "Container doesn't exist");
+ }
+
+ public void testCreateContainerInLocation() throws IOException {
+ final String CONTAINER_NAME2 = "funambol-test-2";
+ final String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
+
+ boolean result;
+
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertFalse(result, "Container exists");
+ result = blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ assertTrue(result, "Container not created");
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertTrue(result, "Container doesn't exist");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
+
+ result = blobStore.containerExists(CONTAINER_NAME2);
+ assertFalse(result, "Container exists");
+ result = blobStore.createContainerInLocation(null, CONTAINER_NAME2);
+ assertTrue(result, "Container not created");
+ result = blobStore.containerExists(CONTAINER_NAME2);
+ assertTrue(result, "Container doesn't exist");
+ TestUtils.directoryExists(TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2, true);
+ }
+
+ public void testPutBlobSimpleName() {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
+ }
+
+ /**
+ * Test of putBlob method with a complex key, with path in the filename, eg
+ * picture/filename.jpg
+ */
+ public void testPutBlobComplexName1() {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("picture/putBlob-", ".jpg"));
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("video/putBlob-", ".jpg"));
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("video/putBlob-", ".jpg"));
+ }
+
+ /**
+ * Test of putBlob method with a complex key, with path in the filename, eg
+ * picture/filename.jpg
+ */
+ public void testPutBlobComplexName2() {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("aa/bb/cc/dd/ee/putBlob-", ".jpg"));
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("aa/bb/cc/dd/ee/putBlob-", ".jpg"));
+ putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg"));
+ }
+
+ public void testBlobExists() throws IOException {
+ boolean result;
+ String blobKey;
+
+ // when location doesn't exists
+ blobKey = TestUtils.createRandomBlobKey();
+ try {
+ blobStore.blobExists(CONTAINER_NAME, blobKey);
+ fail();
+ } catch (ContainerNotFoundException cnfe) {
+ // expected
+ }
+
+ // when location exists
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ result = blobStore.blobExists(CONTAINER_NAME, blobKey);
+ assertFalse(result, "Blob exists");
+
+ // create blob
+ TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload());
+ result = blobStore.blobExists(CONTAINER_NAME, blobKey);
+ assertTrue(result, "Blob doesn't exist");
+
+ // complex path test
+ blobKey = TestUtils.createRandomBlobKey("ss/asdas/", "");
+ result = blobStore.blobExists(CONTAINER_NAME, blobKey);
+ assertFalse(result, "Blob exists");
+ TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload());
+ result = blobStore.blobExists(CONTAINER_NAME, blobKey);
+ assertTrue(result, "Blob doesn't exist");
+ }
+
+ public void testGetBlob_NotExistingContainer() {
+ try {
+ blobStore.getBlob(CONTAINER_NAME, TestUtils.createRandomBlobKey(), null);
+ fail("Retrieve must fail, container does not exist.");
+ } catch (ContainerNotFoundException e) {
+ // correct if arrive here
+ }
+ }
+
+ public void testGetBlob() throws IOException {
+ String blobKey = TestUtils.createRandomBlobKey();
+ GetOptions options = null;
+ Blob resultBlob;
+
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+
+ resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
+ assertNull(resultBlob, "Blob exists");
+
+ // create blob
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, blobKey);
+
+ resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options);
+
+ assertNotNull(resultBlob, "Blob exists");
+ // checks file content
+ ByteSource expectedFile = Files.asByteSource(new File(TARGET_CONTAINER_NAME, blobKey));
+ assertEquals(expectedFile.read(), ByteStreams2.toByteArrayAndClose(resultBlob.getPayload().openStream()),
+ "Blob payload differs from file content");
+ // metadata are verified in the test for blobMetadata, so no need to
+ // perform a complete test here
+ assertNotNull(resultBlob.getMetadata(), "Metadata null");
+ MutableBlobMetadata metadata = resultBlob.getMetadata();
+ assertEquals(blobKey, metadata.getName(), "Wrong blob metadata");
+ }
+
+ public void testBlobMetadata_withDefaultMetadata() throws IOException {
+ String BLOB_KEY = TestUtils.createRandomBlobKey(null, null);
+ // create the blob
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ Blob blob = blobStore.blobBuilder(BLOB_KEY)
+ .payload(TestUtils.getImageForBlobPayload())
+ .build();
+ blobStore.putBlob(CONTAINER_NAME, blob);
+
+ BlobMetadata metadata = blobStore.blobMetadata(CONTAINER_NAME, BLOB_KEY);
+ assertNotNull(metadata, "Metadata null");
+
+ assertEquals(metadata.getName(), BLOB_KEY, "Wrong blob name");
+ assertEquals(metadata.getType(), StorageType.BLOB, "Wrong blob type");
+ assertEquals(metadata.getContentMetadata().getContentType(), "application/unknown", "Wrong blob content-type");
+ assertEquals(base16().lowerCase().encode(metadata.getContentMetadata().getContentMD5()), metadata.getETag(),
+ "Wrong blob MD5");
+ assertEquals(metadata.getLocation(), null, "Wrong blob location");
+ assertEquals(metadata.getProviderId(), null, "Wrong blob provider id");
+ assertEquals(metadata.getUri(), null, "Wrong blob URI");
+ assertNotNull(metadata.getUserMetadata(), "No blob UserMetadata");
+ assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata");
+ // metadata.getLastModified()
+ File file = new File(TARGET_CONTAINER_NAME, BLOB_KEY);
+ assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(file.length()), "Wrong blob size");
+ }
+
+ public void testDeleteContainer_NotExistingContainer() {
+ blobStore.deleteContainer(CONTAINER_NAME);
+ }
+
+ public void testDeleteContainer_EmptyContanier() {
+ boolean result;
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertTrue(result, "Container doesn't exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
+
+ // delete container
+ blobStore.deleteContainer(CONTAINER_NAME);
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertFalse(result, "Container still exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
+ }
+
+ public void testDeleteContainer() throws IOException {
+ boolean result;
+ String CONTAINER_NAME2 = "container-to-delete";
+ String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2;
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ blobStore.createContainerInLocation(null, CONTAINER_NAME2);
+
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertTrue(result, "Container [" + CONTAINER_NAME + "] doesn't exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
+ result = blobStore.containerExists(CONTAINER_NAME2);
+ assertTrue(result, "Container [" + CONTAINER_NAME2 + "] doesn't exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
+
+ // create blobs inside container
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, TestUtils.createRandomBlobKey("testutils-", null),
+ TestUtils.createRandomBlobKey("testutils-", null),
+ TestUtils.createRandomBlobKey("ab123s" + File.separator + "testutils-", null));
+ TestUtils.createBlobsInContainer(CONTAINER_NAME, TestUtils.createRandomBlobKey("testutils-", null),
+ TestUtils.createRandomBlobKey("testutils-", null),
+ TestUtils.createRandomBlobKey("asda123s" + File.separator + "testutils-", null),
+ TestUtils.createRandomBlobKey("123-_3s" + File.separator + "testutils-", null));
+
+ // delete first container
+ blobStore.deleteContainer(CONTAINER_NAME);
+ result = blobStore.containerExists(CONTAINER_NAME);
+ assertFalse(result, "Container [" + CONTAINER_NAME + "] still exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
+ result = blobStore.containerExists(CONTAINER_NAME2);
+ assertTrue(result, "Container [" + CONTAINER_NAME2 + "] still exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME2, true);
+ // delete second container
+ blobStore.deleteContainer(CONTAINER_NAME2);
+ result = blobStore.containerExists(CONTAINER_NAME2);
+ assertFalse(result, "Container [" + CONTAINER_NAME2 + "] still exists");
+ TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false);
+ }
+
+ @Test
+ public void testInvalidContainerName() {
+ String containerName = "file" + File.separator + "system";
+ try {
+ blobStore.createContainerInLocation(null, containerName);
+ fail("Wrong container name not recognized");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ blobStore.containerExists(containerName);
+ fail("Wrong container name not recognized");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testRanges() throws IOException {
+ blobStore.createContainerInLocation(null, CONTAINER_NAME);
+ String input = "abcdefgh";
+ Payload payload;
+ Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(input)).build();
+ blobStore.putBlob(CONTAINER_NAME, blob);
+
+ GetOptions getOptionsRangeStartAt = new GetOptions();
+ getOptionsRangeStartAt.startAt(1);
+ Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
+ payload = blobRangeStartAt.getPayload();
+ try {
+ assertEquals(input.substring(1), Strings2.toStringAndClose(payload.openStream()));
+ } finally {
+ Closeables2.closeQuietly(payload);
+ }
+
+ GetOptions getOptionsRangeTail = new GetOptions();
+ getOptionsRangeTail.tail(3);
+ Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
+ payload = blobRangeTail.getPayload();
+ try {
+ assertEquals(input.substring(5), Strings2.toStringAndClose(payload.openStream()));
+ } finally {
+ Closeables2.closeQuietly(payload);
+ }
+
+ GetOptions getOptionsFragment = new GetOptions();
+ getOptionsFragment.range(4, 6);
+ Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
+ payload = blobFragment.getPayload();
+ try {
+ assertEquals(input.substring(4, 7), Strings2.toStringAndClose(payload.openStream()));
+ } finally {
+ Closeables2.closeQuietly(payload);
+ }
+ }
+
+ /** Test that BlobRequestSigner creates expected URIs. */
+ public void testBlobRequestSigner() throws Exception {
+ String containerName = "container";
+ String blobName = "blob";
+ URI endPoint = new URI("http", "localhost",
+ String.format("/transient/%s/%s", containerName, blobName),
+ /*fragment=*/ null);
+ BlobRequestSigner signer = context.getSigner();
+ HttpRequest request;
+ HttpRequest expected;
+
+ request = signer.signGetBlob(containerName, blobName);
+ expected = HttpRequest.builder()
+ .method("GET")
+ .endpoint(endPoint)
+ .headers(request.getHeaders())
+ .build();
+ assertEquals(expected, request);
+
+ request = signer.signRemoveBlob(containerName, blobName);
+ expected = HttpRequest.builder()
+ .method("DELETE")
+ .endpoint(endPoint)
+ .headers(request.getHeaders())
+ .build();
+ assertEquals(expected, request);
+
+ Blob blob = blobStore.blobBuilder(blobName).forSigning().build();
+ request = signer.signPutBlob(containerName, blob);
+ expected = HttpRequest.builder()
+ .method("PUT")
+ .endpoint(endPoint)
+ .headers(request.getHeaders())
+ .payload(new PhantomPayload())
+ .build();
+ assertEquals(expected, request);
+ }
+
+ // public void testInvalidBlobKey() {
+ // try {
+ // blobStore.newBlob(File.separator + "testwrongblobkey");
+ // fail("Wrong blob key not recognized");
+ // } catch (IllegalArgumentException e) {}
+ //
+ // try {
+ // blobStore.newBlob("testwrongblobkey" + File.separator);
+ // fail("Wrong blob key not recognized");
+ // } catch (IllegalArgumentException e) {}
+ // }
+
+ // ---------------------------------------------------------- Private Methods
+
+ /**
+ * Creates a {@link Blob} object filled with data from a file
+ *
+ * @param keyName
+ * @param fileContent
+ * @return
+ */
+ private Blob createBlob(String keyName, File filePayload) {
+ return blobStore.blobBuilder(keyName).payload(filePayload).build();
+ }
+
+ /**
+ * Tests if container contains only the expected blobs
+ *
+ * @param containerName
+ * @param expectedBlobKeys
+ */
+ private void checkForContainerContent(final String containerName, Set<String> expectedBlobKeys) {
+ checkForContainerContent(containerName, null, expectedBlobKeys);
+ }
+
+ private void checkForContainerContent(final String containerName, String inDirectory, Set<String> expectedBlobKeys) {
+ ListContainerOptions options = ListContainerOptions.Builder.recursive();
+ if (null != inDirectory && !"".equals(inDirectory))
+ options.inDirectory(inDirectory);
+
+ PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options);
+ for (Iterator<? extends StorageMetadata> it = blobsRetrieved.iterator(); it.hasNext();) {
+ // TODO: FluentIterable
+ if (it.next().getType() != StorageType.BLOB) {
+ it.remove();
+ }
+ }
+
+ // nothing expected
+ if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) {
+ assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the container [" + containerName + "]");
+ return;
+ }
+
+ // copies values
+ Set<String> expectedBlobKeysCopy = Sets.newHashSet();
+ for (String value : expectedBlobKeys) {
+ expectedBlobKeysCopy.add(value);
+ }
+ assertEquals(blobsRetrieved.size(), expectedBlobKeysCopy.size(),
+ "Wrong blob number retrieved in the container [" + containerName + "]");
+ for (StorageMetadata data : blobsRetrieved) {
+ String blobName = data.getName();
+ if (!expectedBlobKeysCopy.remove(blobName)) {
+ fail("List for container [" + containerName + "] contains unexpected value [" + blobName + "]");
+ }
+ }
+ assertTrue(expectedBlobKeysCopy.isEmpty(), "List operation for container [" + containerName
+ + "] doesn't return all values.");
+ }
+
+ /**
+ * Create a blob with putBlob method
+ */
+ private void putBlobAndCheckIt(String blobKey) {
+ Blob blob;
+
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false);
+
+ // create the blob
+ blob = createBlob(blobKey, TestUtils.getImageForBlobPayload());
+ String eTag = blobStore.putBlob(CONTAINER_NAME, blob);
+ assertNotNull(eTag, "putBlob result null");
+ assertNotSame(eTag, "", "putBlob result empty");
+
+ // checks if the blob exists
+ TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, true);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/a22a7252/apis/filesystem/src/test/resources/logging.properties
----------------------------------------------------------------------
diff --git a/apis/filesystem/src/test/resources/logging.properties b/apis/filesystem/src/test/resources/logging.properties
index 2b76983..6f45f70 100644
--- a/apis/filesystem/src/test/resources/logging.properties
+++ b/apis/filesystem/src/test/resources/logging.properties
@@ -25,5 +25,3 @@
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-org.jclouds.filesystem.FilesystemAsyncBlobStore.level=ALL
-org.jclouds.filesystem.FilesystemAsyncBlobStore.handler=java.util.logging.ConsoleHandler