Issue 154: added Transient blobstore

This commit is contained in:
Adrian Cole 2010-03-09 09:17:33 -08:00
parent cb0928afae
commit e04784373e
27 changed files with 238 additions and 195 deletions

View File

@ -26,7 +26,7 @@ import org.jclouds.atmosonline.saas.AtmosStorage;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.internal.StubAtmosStorageAsyncClient;
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.rest.ConfiguresRestClient;
@ -42,7 +42,7 @@ import com.google.inject.Provides;
public class AtmosStorageStubClientModule extends AbstractModule {
protected void configure() {
install(new StubBlobStoreModule());
install(new TransientBlobStoreModule());
bind(AtmosStorageAsyncClient.class).to(StubAtmosStorageAsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(AtmosStorage.class).toInstance(
URI.create("https://localhost/azurestub"));

View File

@ -40,10 +40,10 @@ import org.jclouds.atmosonline.saas.domain.DirectoryEntry;
import org.jclouds.atmosonline.saas.domain.SystemMetadata;
import org.jclouds.atmosonline.saas.domain.UserMetadata;
import org.jclouds.atmosonline.saas.options.ListOptions;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.http.options.GetOptions;
import com.google.common.base.Function;
@ -58,7 +58,7 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
public class StubAtmosStorageAsyncClient implements AtmosStorageAsyncClient {
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
private final StubAsyncBlobStore blobStore;
private final TransientAsyncBlobStore blobStore;
private final AtmosObject.Factory objectProvider;
private final ObjectToBlob object2Blob;
private final BlobToObject blob2Object;
@ -67,7 +67,7 @@ public class StubAtmosStorageAsyncClient implements AtmosStorageAsyncClient {
private final ResourceMetadataListToDirectoryEntryList resource2ObjectList;
@Inject
private StubAtmosStorageAsyncClient(StubAsyncBlobStore blobStore,
private StubAtmosStorageAsyncClient(TransientAsyncBlobStore blobStore,
AtmosObject.Factory objectProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob,
BlobToObject blob2Object, BlobMetadataToObject blob2ObjectInfo,

View File

@ -26,7 +26,7 @@ import org.jclouds.aws.s3.S3;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.internal.StubS3AsyncClient;
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.ConfiguresRestClient;
@ -44,7 +44,7 @@ public class S3StubClientModule extends AbstractModule {
protected void configure() {
install(new ParserModule());
install(new StubBlobStoreModule());
install(new TransientBlobStoreModule());
bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("https://localhost/s3stub"));
}

View File

@ -59,11 +59,11 @@ import org.jclouds.aws.s3.options.PutBucketOptions;
import org.jclouds.aws.s3.options.PutObjectOptions;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.concurrent.ConcurrentUtils;
import org.jclouds.date.DateService;
@ -95,7 +95,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs;
@Inject
private StubS3AsyncClient(StubAsyncBlobStore blobStore,
private StubS3AsyncClient(TransientAsyncBlobStore blobStore,
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
DateService dateService, S3Object.Factory objectProvider, Blob.Factory blobProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob,
@ -156,25 +156,25 @@ public class StubS3AsyncClient implements S3AsyncClient {
Blob object = source.get(sourceObject);
if (options.getIfMatch() != null) {
if (!object.getMetadata().getETag().equals(options.getIfMatch()))
return immediateFailedFuture(StubAsyncBlobStore.returnResponseException(412));
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
}
if (options.getIfNoneMatch() != null) {
if (object.getMetadata().getETag().equals(options.getIfNoneMatch()))
return immediateFailedFuture(StubAsyncBlobStore.returnResponseException(412));
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
}
if (options.getIfModifiedSince() != null) {
Date modifiedSince = dateService.rfc822DateParse(options.getIfModifiedSince());
if (modifiedSince.after(object.getMetadata().getLastModified()))
return immediateFailedFuture(StubAsyncBlobStore.returnResponseException(412));
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
}
if (options.getIfUnmodifiedSince() != null) {
Date unmodifiedSince = dateService.rfc822DateParse(options.getIfUnmodifiedSince());
if (unmodifiedSince.before(object.getMetadata().getLastModified()))
return immediateFailedFuture(StubAsyncBlobStore.returnResponseException(412));
return immediateFailedFuture(TransientAsyncBlobStore.returnResponseException(412));
}
Blob sourceS3 = source.get(sourceObject);
MutableBlobMetadata newMd = StubAsyncBlobStore.copy(sourceS3.getMetadata(),
MutableBlobMetadata newMd = TransientAsyncBlobStore.copy(sourceS3.getMetadata(),
destinationObject);
if (options.getAcl() != null)
keyToAcl.put(destinationBucket + "/" + destinationObject, options.getAcl());
@ -183,7 +183,7 @@ public class StubS3AsyncClient implements S3AsyncClient {
Blob newBlob = blobProvider.create(newMd);
newBlob.setPayload(sourceS3.getContent());
dest.put(destinationObject, newBlob);
return immediateFuture((ObjectMetadata) blob2ObjectMetadata.apply(StubAsyncBlobStore
return immediateFuture((ObjectMetadata) blob2ObjectMetadata.apply(TransientAsyncBlobStore
.copy(newMd)));
}
return immediateFailedFuture(new KeyNotFoundException(sourceBucket, sourceObject,

View File

@ -26,7 +26,7 @@ import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.internal.StubAzureBlobAsyncClient;
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.ConfiguresRestClient;
@ -44,7 +44,7 @@ public class AzureBlobStubClientModule extends AbstractModule {
protected void configure() {
install(new ParserModule());
install(new StubBlobStoreModule());
install(new TransientBlobStoreModule());
bind(AzureBlobAsyncClient.class).to(StubAzureBlobAsyncClient.class).asEagerSingleton();
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(
URI.create("https://localhost/azurestub"));

View File

@ -45,10 +45,10 @@ import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
import org.jclouds.azure.storage.domain.BoundedSet;
import org.jclouds.azure.storage.domain.internal.BoundedHashSet;
import org.jclouds.azure.storage.options.ListOptions;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.http.options.GetOptions;
import com.google.common.base.Function;
@ -63,7 +63,7 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
public class StubAzureBlobAsyncClient implements AzureBlobAsyncClient {
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
private final StubAsyncBlobStore blobStore;
private final TransientAsyncBlobStore blobStore;
private final AzureBlob.Factory objectProvider;
private final AzureBlobToBlob object2Blob;
private final BlobToAzureBlob blob2Object;
@ -73,7 +73,7 @@ public class StubAzureBlobAsyncClient implements AzureBlobAsyncClient {
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs;
@Inject
private StubAzureBlobAsyncClient(StubAsyncBlobStore blobStore,
private StubAzureBlobAsyncClient(TransientAsyncBlobStore blobStore,
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
AzureBlob.Factory objectProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, AzureBlobToBlob object2Blob,

View File

@ -108,7 +108,7 @@
<systemProperties>
<property>
<name>jclouds.test.initializer</name>
<value>org.jclouds.blobstore.integration.StubTestInitializer</value>
<value>org.jclouds.blobstore.integration.TransientBlobStoreTestInitializer</value>
</property>
<property>
<name>jclouds.blobstore.httpstream.url</name>

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore.integration.internal;
package org.jclouds.blobstore;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
@ -50,9 +50,6 @@ import javax.inject.Named;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.MutableBlobMetadata;
@ -95,7 +92,7 @@ import com.google.inject.internal.Nullable;
* @author Adrian Cole
* @author James Murty
*/
public class StubAsyncBlobStore extends BaseAsyncBlobStore {
public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
protected final DateService dateService;
protected final EncryptionService encryptionService;
@ -105,7 +102,7 @@ public class StubAsyncBlobStore extends BaseAsyncBlobStore {
protected final Factory blobFactory;
@Inject
protected StubAsyncBlobStore(BlobStoreContext context, DateService dateService,
protected TransientAsyncBlobStore(BlobStoreContext context, DateService dateService,
EncryptionService encryptionService,
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
@ -267,14 +264,6 @@ public class StubAsyncBlobStore extends BaseAsyncBlobStore {
return newMd;
}
// public BlobMetadata metadata(final String container, final String key) {
// if (!getContainerToBlobs().containsKey(container))
// return immediateFailedFuture(new ContainerNotFoundException(container));
// Map<String, Blob> realContents = getContainerToBlobs().get(container);
// if (!realContents.containsKey(key))
// return immediateFailedFuture(new KeyNotFoundException(container, key));
// return copy(realContents.get(key).getMetadata());
// }
/**
* {@inheritDoc}
*/

View File

@ -16,36 +16,45 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore.integration;
package org.jclouds.blobstore;
import java.net.URI;
import java.util.List;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.blobstore.config.TransientBlobStoreContextModule;
import org.jclouds.blobstore.config.TransientBlobStoreModule;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Builds properties used in Stub Connections
*
* @author Adrian Cole
*/
public class StubPropertiesBuilder extends PropertiesBuilder {
public class TransientBlobStoreContextBuilder extends
BlobStoreContextBuilder<AsyncBlobStore, BlobStore> {
public StubPropertiesBuilder(Properties properties) {
super(properties);
/**
* This is only to have the same syntax.
*
*/
public TransientBlobStoreContextBuilder(Properties props) {
this();
}
public StubPropertiesBuilder(String id, String secret) {
super();
public TransientBlobStoreContextBuilder() {
super(new TypeLiteral<AsyncBlobStore>() {
}, new TypeLiteral<BlobStore>() {
});
}
@Override
public PropertiesBuilder withCredentials(String account, String key) {
return this;
public void addContextModule(List<Module> modules) {
modules.add(new TransientBlobStoreContextModule());
}
@Override
public PropertiesBuilder withEndpoint(URI endpoint) {
return this;
protected void addClientModule(List<Module> modules) {
modules.add(new TransientBlobStoreModule());
}
}
}

View File

@ -0,0 +1,36 @@
package org.jclouds.blobstore;
import java.net.URI;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
/**
* Builds properties used in transient blobstores
*
* @author Adrian Cole
*/
public class TransientBlobStorePropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
return properties;
}
public TransientBlobStorePropertiesBuilder(Properties properties) {
super(properties);
}
public TransientBlobStorePropertiesBuilder(String id, String secret) {
super();
withCredentials(id, secret);
}
public TransientBlobStorePropertiesBuilder withCredentials(String id, String secret) {
return this;
}
public TransientBlobStorePropertiesBuilder withEndpoint(URI endpoint) {
return this;
}
}

View File

@ -0,0 +1,67 @@
package org.jclouds.blobstore.config;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.concurrent.Timeout;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link TransientBlobStoreContext}; requires {@link TransientAsyncBlobStore} bound.
*
* @author Adrian Cole
*/
public class TransientBlobStoreContextModule extends AbstractModule {
@Override
protected void configure() {
install(new BlobStoreObjectModule<AsyncBlobStore, BlobStore>(
new TypeLiteral<AsyncBlobStore>() {
}, new TypeLiteral<BlobStore>() {
}));
install(new BlobStoreMapModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
bind(AsyncBlobStore.class).to(TransientAsyncBlobStore.class).asEagerSingleton();
bind(BlobStoreContext.class)
.to(
new TypeLiteral<BlobStoreContextImpl<AsyncBlobStore, BlobStore>>() {
}).in(Scopes.SINGLETON);
}
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
private static interface TransientBlobStore extends BlobStore {
}
@Provides
@Singleton
public BlobStore provideClient(AsyncBlobStore client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(TransientBlobStore.class, client);
}
@Provides
@Singleton
RestContext<AsyncBlobStore, BlobStore> provideContext(Closer closer, final AsyncBlobStore async,
final BlobStore sync) {
return new RestContextImpl<AsyncBlobStore, BlobStore>(closer, async, sync, URI
.create("http://localhost/transient"), System.getProperty("user.name"));
}
}

View File

@ -16,21 +16,21 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore.integration.config;
package org.jclouds.blobstore.config;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.jclouds.Constants;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.util.Jsr330;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
public class StubBlobStoreModule extends AbstractModule {
public class TransientBlobStoreModule extends AbstractModule {
// must be singleton for all threads and all objects or tests may fail;
static final ConcurrentHashMap<String, ConcurrentMap<String, Blob>> map = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>();
@ -39,7 +39,7 @@ public class StubBlobStoreModule extends AbstractModule {
protected void configure() {
bind(new TypeLiteral<ConcurrentMap<String, ConcurrentMap<String, Blob>>>() {
}).toInstance(map);
bind(StubAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(TransientAsyncBlobStore.class).in(Scopes.SINGLETON);
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to(0);
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to(0);
}

View File

@ -27,3 +27,5 @@ cloudfiles.contextbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesContextBuil
cloudfiles.propertiesbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder
s3.contextbuilder=org.jclouds.aws.s3.S3ContextBuilder
s3.propertiesbuilder=org.jclouds.aws.s3.S3PropertiesBuilder
transient.contextbuilder=org.jclouds.blobstore.TransientBlobStoreContextBuilder
transient.propertiesbuilder=org.jclouds.blobstore.TransientBlobStorePropertiesBuilder

View File

@ -1,9 +1,9 @@
(ns org.jclouds.blobstore-test
(:use [org.jclouds.blobstore] :reload-all)
(:use clojure.test)
(:import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder))
(:import org.jclouds.blobstore.TransientBlobStoreContextBuilder))
(def stub-context (.buildBlobStoreContext (StubBlobStoreContextBuilder.)))
(def stub-context (.buildBlobStoreContext (TransientBlobStoreContextBuilder.)))
(def stub-blobstore (.getBlobStore stub-context))
(defn clean-stub-fixture [f]

View File

@ -0,0 +1,52 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.io.Resources;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "blobstore.PropertiesTest")
public class PropertiesTest {
private Properties properties;
@BeforeTest
public void setUp() throws IOException {
properties = new Properties();
properties.load(Resources.newInputStreamSupplier(
Resources.getResource("blobstore.properties")).getInput());
}
public void testTransient() {
assertEquals(properties.getProperty("transient.contextbuilder"),
TransientBlobStoreContextBuilder.class.getName());
assertEquals(properties.getProperty("transient.propertiesbuilder"),
TransientBlobStorePropertiesBuilder.class.getName());
}
}

View File

@ -27,9 +27,9 @@ import java.net.URI;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.jclouds.blobstore.TransientBlobStoreContextBuilder;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.Blob.Factory;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
@ -48,7 +48,7 @@ public class BindBlobToMultipartFormTest {
public static final Blob TEST_BLOB;
static {
blobProvider = new StubBlobStoreContextBuilder().buildInjector().getInstance(
blobProvider = new TransientBlobStoreContextBuilder().buildInjector().getInstance(
Blob.Factory.class);
StringBuilder builder = new StringBuilder("--");
addData(BOUNDRY, "hello", builder);

View File

@ -1,115 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore.integration;
import java.net.URI;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextBuilder;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.concurrent.Timeout;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
public class StubBlobStoreContextBuilder extends BlobStoreContextBuilder<AsyncBlobStore, BlobStore> {
/**
* This is only to have the same syntax.
*
*/
public StubBlobStoreContextBuilder(Properties props) {
this();
}
public StubBlobStoreContextBuilder() {
super(new TypeLiteral<AsyncBlobStore>() {
}, new TypeLiteral<BlobStore>() {
});
}
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
private static interface StubBlobStore extends BlobStore {
}
@Override
public void addContextModule(List<Module> modules) {
modules.add(new BlobStoreObjectModule<AsyncBlobStore, BlobStore>(
new TypeLiteral<AsyncBlobStore>() {
}, new TypeLiteral<BlobStore>() {
}));
modules.add(new BlobStoreMapModule());
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(AsyncBlobStore.class).to(StubAsyncBlobStore.class).asEagerSingleton();
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AsyncBlobStore, BlobStore>>(){}).in(Scopes.SINGLETON);
}
@SuppressWarnings("unused")
@Provides
@Singleton
public BlobStore provideClient(AsyncBlobStore client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(StubBlobStore.class, client);
}
@SuppressWarnings("unused")
@Provides
@Singleton
RestContext<AsyncBlobStore, BlobStore> provideContext(Closer closer,
final AsyncBlobStore async, final BlobStore sync) {
return new RestContextImpl<AsyncBlobStore, BlobStore>(closer, async, sync, URI
.create("http://localhost/blobstub"), "foo");
}
});
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new StubBlobStoreModule());
}
}

View File

@ -26,7 +26,7 @@ import org.testng.annotations.Test;
* @author James Murty
* @author Adrian Cole
*/
@Test(groups = { "integration" }, testName = "blobstore.StubBlobIntegrationTest")
public class StubBlobIntegrationTest extends BaseBlobIntegrationTest {
@Test(groups = { "integration" }, testName = "blobstore.TransientBlobIntegrationTest")
public class TransientBlobIntegrationTest extends BaseBlobIntegrationTest {
}

View File

@ -25,7 +25,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubBlobMapIntegrationTest")
public class StubBlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
@Test(groups = { "integration", "live" }, testName = "blobstore.TransientBlobMapIntegrationTest")
public class TransientBlobMapIntegrationTest extends BaseBlobMapIntegrationTest {
}

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.blobstore.integration;
import java.io.IOException;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.integration.internal.BaseTestInitializer;
import com.google.inject.Module;
@ -27,17 +30,17 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class StubTestInitializer extends BaseTestInitializer {
public class TransientBlobStoreTestInitializer extends BaseTestInitializer {
@Override
protected BlobStoreContext createLiveContext(Module configurationModule, String url, String app,
String account, String key) {
String account, String key) throws IOException {
return createStubContext();
}
@Override
protected BlobStoreContext createStubContext() {
return new StubBlobStoreContextBuilder().buildBlobStoreContext();
protected BlobStoreContext createStubContext() throws IOException {
return new BlobStoreContextFactory().createContext("transient", "foo", "bar");
}
}

View File

@ -25,7 +25,7 @@ import org.testng.annotations.Test;
* @author James Murty
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubContainerIntegrationTest")
public class StubContainerIntegrationTest extends BaseContainerIntegrationTest {
@Test(groups = { "integration", "live" }, testName = "blobstore.TransientContainerIntegrationTest")
public class TransientContainerIntegrationTest extends BaseContainerIntegrationTest {
}

View File

@ -24,7 +24,7 @@ import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubInputStreamMapIntegrationTest")
public class StubInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
@Test(groups = { "integration", "live" }, testName = "blobstore.TransientInputStreamMapIntegrationTest")
public class TransientInputStreamMapIntegrationTest extends BaseInputStreamMapIntegrationTest {
}

View File

@ -24,7 +24,7 @@ import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = { "integration", "live" }, testName = "blobstore.StubServiceIntegrationTest")
public class StubServiceIntegrationTest extends BaseServiceIntegrationTest {
@Test(groups = { "integration", "live" }, testName = "blobstore.TransientServiceIntegrationTest")
public class TransientServiceIntegrationTest extends BaseServiceIntegrationTest {
}

View File

@ -48,7 +48,7 @@ public abstract class BaseTestInitializer {
}
}
protected abstract BlobStoreContext createStubContext();
protected abstract BlobStoreContext createStubContext() throws IOException;
protected abstract BlobStoreContext createLiveContext(Module configurationModule, String url,
String app, String account, String key) throws IOException;

View File

@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.TransientBlobStoreContextBuilder;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -46,7 +46,7 @@ public class BaseBlobMapTest {
@BeforeClass
void addDefaultObjectsSoThatTestsWillPass() {
context = new StubBlobStoreContextBuilder().buildBlobStoreContext();
context = new TransientBlobStoreContextBuilder().buildBlobStoreContext();
map = (InputStreamMapImpl) context.createInputStreamMap("test");
}

View File

@ -20,7 +20,7 @@ package org.jclouds.rackspace.cloudfiles.config;
import javax.inject.Singleton;
import org.jclouds.blobstore.integration.config.StubBlobStoreModule;
import org.jclouds.blobstore.config.TransientBlobStoreModule;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
@ -36,7 +36,7 @@ public class CloudFilesStubClientModule extends AbstractModule {
protected void configure() {
install(new ParserModule());
install(new StubBlobStoreModule());
install(new TransientBlobStoreModule());
bind(CloudFilesAsyncClient.class).to(StubCloudFilesAsyncClient.class).asEagerSingleton();
}

View File

@ -30,11 +30,11 @@ import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
@ -64,7 +64,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@Singleton
public class StubCloudFilesAsyncClient implements CloudFilesAsyncClient {
private final HttpGetOptionsListToGetOptions httpGetOptionsConverter;
private final StubAsyncBlobStore blobStore;
private final TransientAsyncBlobStore blobStore;
private final CFObject.Factory objectProvider;
private final ObjectToBlob object2Blob;
private final BlobToObject blob2Object;
@ -74,7 +74,7 @@ public class StubCloudFilesAsyncClient implements CloudFilesAsyncClient {
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs;
@Inject
private StubCloudFilesAsyncClient(StubAsyncBlobStore blobStore,
private StubCloudFilesAsyncClient(TransientAsyncBlobStore blobStore,
ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs,
CFObject.Factory objectProvider,
HttpGetOptionsListToGetOptions httpGetOptionsConverter, ObjectToBlob object2Blob,