mirror of https://github.com/apache/jclouds.git
Replaced the deprecated BlobStoreContextFactory with the new-style BlobStoreContextBuilder for runatcloud-tweetstore
This commit is contained in:
parent
3b2e6ea796
commit
dcc8e2f9ef
|
@ -39,7 +39,7 @@ import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.demo.paas.PlatformServices;
|
import org.jclouds.demo.paas.PlatformServices;
|
||||||
import org.jclouds.demo.paas.service.taskqueue.TaskQueue;
|
import org.jclouds.demo.paas.service.taskqueue.TaskQueue;
|
||||||
import org.jclouds.demo.tweetstore.config.util.CredentialsCollector;
|
import org.jclouds.demo.tweetstore.config.util.CredentialsCollector;
|
||||||
|
@ -70,7 +70,7 @@ import com.google.inject.servlet.ServletModule;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
private Map<String, BlobStoreContext> providerTypeToBlobStoreMap;
|
private Map<String, BlobStoreContext<?, ?>> providerTypeToBlobStoreMap;
|
||||||
private Twitter twitterClient;
|
private Twitter twitterClient;
|
||||||
private String container;
|
private String container;
|
||||||
private TaskQueue queue;
|
private TaskQueue queue;
|
||||||
|
@ -78,7 +78,6 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
BlobStoreContextFactory blobStoreContextFactory = new BlobStoreContextFactory();
|
|
||||||
ServletContext servletContext = servletContextEvent.getServletContext();
|
ServletContext servletContext = servletContextEvent.getServletContext();
|
||||||
|
|
||||||
Properties props = new PropertiesLoader(servletContext).get();
|
Properties props = new PropertiesLoader(servletContext).get();
|
||||||
|
@ -101,7 +100,8 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
// instantiate and store references to all blobstores by provider name
|
// instantiate and store references to all blobstores by provider name
|
||||||
providerTypeToBlobStoreMap = Maps.newHashMap();
|
providerTypeToBlobStoreMap = Maps.newHashMap();
|
||||||
for (String hint : getBlobstoreContexts(props)) {
|
for (String hint : getBlobstoreContexts(props)) {
|
||||||
providerTypeToBlobStoreMap.put(hint, blobStoreContextFactory.createContext(hint, modules, props));
|
providerTypeToBlobStoreMap.put(hint, BlobStoreContextBuilder
|
||||||
|
.newBuilder(hint).modules(modules).overrides(props).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a queue for submitting store tweet requests and the application's base URL
|
// get a queue for submitting store tweet requests and the application's base URL
|
||||||
|
@ -127,7 +127,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
return Guice.createInjector(new ServletModule() {
|
return Guice.createInjector(new ServletModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
bind(new TypeLiteral<Map<String, BlobStoreContext>>() {})
|
bind(new TypeLiteral<Map<String, BlobStoreContext<?, ?>>>() {})
|
||||||
.toInstance(providerTypeToBlobStoreMap);
|
.toInstance(providerTypeToBlobStoreMap);
|
||||||
bind(Twitter.class).toInstance(twitterClient);
|
bind(Twitter.class).toInstance(twitterClient);
|
||||||
bind(TaskQueue.class).toInstance(queue);
|
bind(TaskQueue.class).toInstance(queue);
|
||||||
|
@ -144,7 +144,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||||
for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) {
|
for (BlobStoreContext<?, ?> context : providerTypeToBlobStoreMap.values()) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
queue.destroy();
|
queue.destroy();
|
||||||
|
|
|
@ -54,14 +54,14 @@ public class AddTweetsController extends HttpServlet implements
|
||||||
|
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 3888348023150822683L;
|
private static final long serialVersionUID = 3888348023150822683L;
|
||||||
private final Map<String, BlobStoreContext> contexts;
|
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
||||||
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
|
private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AddTweetsController(Map<String, BlobStoreContext> contexts,
|
AddTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
||||||
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class EnqueueStoresController extends HttpServlet {
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public EnqueueStoresController(Map<String, BlobStoreContext> contexts, TaskQueue taskQueue,
|
public EnqueueStoresController(Map<String, BlobStoreContext<?, ?>> contexts, TaskQueue taskQueue,
|
||||||
@Named(PaasConstants.PROPERTY_PLATFORM_BASE_URL) String baseUrl) {
|
@Named(PaasConstants.PROPERTY_PLATFORM_BASE_URL) String baseUrl) {
|
||||||
contextNames = contexts.keySet();
|
contextNames = contexts.keySet();
|
||||||
this.taskQueue = taskQueue;
|
this.taskQueue = taskQueue;
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 7215420527854203714L;
|
private static final long serialVersionUID = 7215420527854203714L;
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext> contexts;
|
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
||||||
private final Twitter client;
|
private final Twitter client;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public StoreTweetsController(Map<String, BlobStoreContext> contexts,
|
public StoreTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) {
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
|
@ -93,7 +93,7 @@ public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void addMyTweets(String contextName, Iterable<Status> responseList) {
|
public void addMyTweets(String contextName, Iterable<Status> responseList) {
|
||||||
BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in "
|
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in "
|
||||||
+ contexts.keySet());
|
+ contexts.keySet());
|
||||||
BlobMap map = context.createBlobMap(container);
|
BlobMap map = context.createBlobMap(container);
|
||||||
for (Status status : responseList) {
|
for (Status status : responseList) {
|
||||||
|
|
|
@ -39,11 +39,11 @@ import com.google.common.collect.Iterables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
|
public class ServiceToStoredTweetStatuses implements Function<String, Iterable<StoredTweetStatus>> {
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext> contexts;
|
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext> contexts,
|
public ServiceToStoredTweetStatuses(Map<String, BlobStoreContext<?, ?>> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
@ -53,7 +53,7 @@ public class ServiceToStoredTweetStatuses implements Function<String, Iterable<S
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
public Iterable<StoredTweetStatus> apply(String service) {
|
public Iterable<StoredTweetStatus> apply(String service) {
|
||||||
BlobStoreContext context = contexts.get(service);
|
BlobStoreContext<?, ?> context = contexts.get(service);
|
||||||
String host = context.getProviderSpecificContext().getEndpoint().getHost();
|
String host = context.getProviderSpecificContext().getEndpoint().getHost();
|
||||||
try {
|
try {
|
||||||
BlobMap blobMap = context.createBlobMap(container);
|
BlobMap blobMap = context.createBlobMap(container);
|
||||||
|
|
|
@ -26,7 +26,8 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
|
import org.jclouds.blobstore.TransientApiMetadata;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
||||||
import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses;
|
import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses;
|
||||||
|
@ -45,11 +46,12 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class AddTweetsControllerTest {
|
public class AddTweetsControllerTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
|
Map<String, BlobStoreContext<?, ?>> createServices(String container) throws InterruptedException,
|
||||||
ExecutionException {
|
ExecutionException {
|
||||||
Map<String, BlobStoreContext> services = Maps.newHashMap();
|
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
|
||||||
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext context = new BlobStoreContextFactory().createContext("transient", "dummy", "dummy");
|
BlobStoreContext<?, ?> context = BlobStoreContextBuilder.newBuilder(transientApiMetadata).build();
|
||||||
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().blobBuilder("1").build();
|
Blob blob = context.getAsyncBlobStore().blobBuilder("1").build();
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
|
@ -62,7 +64,7 @@ public class AddTweetsControllerTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
String container = "container";
|
String container = "container";
|
||||||
Map<String, BlobStoreContext> contexts = createServices(container);
|
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
|
||||||
|
|
||||||
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
||||||
AddTweetsController controller = new AddTweetsController(contexts, function);
|
AddTweetsController controller = new AddTweetsController(contexts, function);
|
||||||
|
|
|
@ -24,7 +24,8 @@ import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
|
import org.jclouds.blobstore.TransientApiMetadata;
|
||||||
import org.jclouds.demo.paas.RunnableHttpRequest;
|
import org.jclouds.demo.paas.RunnableHttpRequest;
|
||||||
import org.jclouds.demo.paas.RunnableHttpRequest.Factory;
|
import org.jclouds.demo.paas.RunnableHttpRequest.Factory;
|
||||||
import org.jclouds.demo.paas.service.taskqueue.TaskQueue;
|
import org.jclouds.demo.paas.service.taskqueue.TaskQueue;
|
||||||
|
@ -42,15 +43,16 @@ import com.google.common.collect.ImmutableMultimap;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class EnqueueStoresControllerTest {
|
public class EnqueueStoresControllerTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext> createBlobStores() {
|
Map<String, BlobStoreContext<?, ?>> createBlobStores() {
|
||||||
Map<String, BlobStoreContext> contexts = ImmutableMap.of(
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
"test1", new BlobStoreContextFactory().createContext("transient", "dummy", "dummy"),
|
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap.<String, BlobStoreContext<?, ?>>of(
|
||||||
"test2", new BlobStoreContextFactory().createContext("transient", "dummy", "dummy"));
|
"test1", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build(),
|
||||||
|
"test2", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build());
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnqueueStores() {
|
public void testEnqueueStores() {
|
||||||
Map<String, BlobStoreContext> stores = createBlobStores();
|
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
|
||||||
TaskQueue taskQueue = createMock(TaskQueue.class);
|
TaskQueue taskQueue = createMock(TaskQueue.class);
|
||||||
Factory httpRequestFactory = createMock(Factory.class);
|
Factory httpRequestFactory = createMock(Factory.class);
|
||||||
EnqueueStoresController function = new EnqueueStoresController(stores,
|
EnqueueStoresController function = new EnqueueStoresController(stores,
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.demo.tweetstore.controller;
|
package org.jclouds.demo.tweetstore.controller;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.classextension.EasyMock.replay;
|
import static org.easymock.EasyMock.verify;
|
||||||
import static org.easymock.classextension.EasyMock.verify;
|
|
||||||
import static org.jclouds.util.Strings2.toStringAndClose;
|
import static org.jclouds.util.Strings2.toStringAndClose;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
|
import org.jclouds.blobstore.TransientApiMetadata;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -56,18 +57,19 @@ public class StoreTweetsControllerTest {
|
||||||
return createMock(Twitter.class);
|
return createMock(Twitter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, BlobStoreContext> createBlobStores() throws InterruptedException, ExecutionException {
|
Map<String, BlobStoreContext<?, ?>> createBlobStores() throws InterruptedException, ExecutionException {
|
||||||
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext> of("test1",
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
new BlobStoreContextFactory().createContext("transient", "dummy", "dummy"), "test2",
|
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap.<String, BlobStoreContext<?, ?>>of(
|
||||||
new BlobStoreContextFactory().createContext("transient", "dummy", "dummy"));
|
"test1", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build(),
|
||||||
for (BlobStoreContext blobstore : contexts.values()) {
|
"test2", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build());
|
||||||
|
for (BlobStoreContext<?, ?> blobstore : contexts.values()) {
|
||||||
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
|
blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get();
|
||||||
}
|
}
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
Map<String, BlobStoreContext> stores = createBlobStores();
|
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
|
||||||
StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter());
|
StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter());
|
||||||
|
|
||||||
User frank = createMock(User.class);
|
User frank = createMock(User.class);
|
||||||
|
@ -99,7 +101,7 @@ public class StoreTweetsControllerTest {
|
||||||
verify(jimmy);
|
verify(jimmy);
|
||||||
verify(jimmyStatus);
|
verify(jimmyStatus);
|
||||||
|
|
||||||
for (Entry<String, BlobStoreContext> entry : stores.entrySet()) {
|
for (Entry<String, BlobStoreContext<?, ?>> entry : stores.entrySet()) {
|
||||||
BlobMap map = entry.getValue().createBlobMap("favo");
|
BlobMap map = entry.getValue().createBlobMap("favo");
|
||||||
Blob frankBlob = map.get("1");
|
Blob frankBlob = map.get("1");
|
||||||
assertEquals(frankBlob.getMetadata().getName(), "1");
|
assertEquals(frankBlob.getMetadata().getName(), "1");
|
||||||
|
|
|
@ -25,7 +25,8 @@ import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
|
import org.jclouds.blobstore.TransientApiMetadata;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
||||||
import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
||||||
|
@ -40,7 +41,8 @@ import org.testng.annotations.Test;
|
||||||
public class KeyToStoredTweetStatusTest {
|
public class KeyToStoredTweetStatusTest {
|
||||||
|
|
||||||
BlobMap createMap() throws InterruptedException, ExecutionException {
|
BlobMap createMap() throws InterruptedException, ExecutionException {
|
||||||
BlobStoreContext context = new BlobStoreContextFactory().createContext("transient", "dummy", "dummy");
|
BlobStoreContext<?, ?> context =
|
||||||
|
BlobStoreContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build();
|
||||||
context.getBlobStore().createContainerInLocation(null, "test1");
|
context.getBlobStore().createContainerInLocation(null, "test1");
|
||||||
return context.createBlobMap("test1");
|
return context.createBlobMap("test1");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
|
import org.jclouds.blobstore.TransientApiMetadata;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
||||||
import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
||||||
|
@ -42,12 +43,12 @@ import com.google.common.collect.Iterables;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ServiceToStoredTweetStatusesTest {
|
public class ServiceToStoredTweetStatusesTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext> createServices(String container) throws InterruptedException,
|
Map<String, BlobStoreContext<?, ?>> createServices(String container) throws InterruptedException,
|
||||||
ExecutionException {
|
ExecutionException {
|
||||||
Map<String, BlobStoreContext> services = Maps.newHashMap();
|
Map<String, BlobStoreContext<?, ?>> services = Maps.newHashMap();
|
||||||
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext context = new BlobStoreContextFactory().createContext("transient",
|
BlobStoreContext<?, ?> context = BlobStoreContextBuilder.newBuilder(transientApiMetadata).build();
|
||||||
"dummy", "dummy");
|
|
||||||
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
context.getAsyncBlobStore().createContainerInLocation(null, container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().blobBuilder("1").build();
|
Blob blob = context.getAsyncBlobStore().blobBuilder("1").build();
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
|
@ -60,7 +61,7 @@ public class ServiceToStoredTweetStatusesTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
String container = "container";
|
String container = "container";
|
||||||
Map<String, BlobStoreContext> contexts = createServices(container);
|
Map<String, BlobStoreContext<?, ?>> contexts = createServices(container);
|
||||||
|
|
||||||
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
@ -73,7 +73,7 @@ public class TweetStoreLiveTest {
|
||||||
|
|
||||||
RunAtCloudServer server;
|
RunAtCloudServer server;
|
||||||
private URL url;
|
private URL url;
|
||||||
private Map<String, BlobStoreContext> contexts;
|
private Map<String, BlobStoreContext<?, ?>> contexts;
|
||||||
private String container;
|
private String container;
|
||||||
private static final Iterable<String> blobstores =
|
private static final Iterable<String> blobstores =
|
||||||
Splitter.on(',').split(getRequiredSystemProperty(PROPERTY_TWEETSTORE_BLOBSTORES));
|
Splitter.on(',').split(getRequiredSystemProperty(PROPERTY_TWEETSTORE_BLOBSTORES));
|
||||||
|
@ -92,13 +92,13 @@ public class TweetStoreLiveTest {
|
||||||
// example of an ad-hoc client configuration
|
// example of an ad-hoc client configuration
|
||||||
addConfigurationForTwitter(props);
|
addConfigurationForTwitter(props);
|
||||||
|
|
||||||
final BlobStoreContextFactory factory = new BlobStoreContextFactory();
|
|
||||||
// for testing, capture logs.
|
// for testing, capture logs.
|
||||||
final Set<Module> wiring = ImmutableSet.<Module> of(new Log4JLoggingModule());
|
final Set<Module> wiring = ImmutableSet.<Module> of(new Log4JLoggingModule());
|
||||||
this.contexts = Maps.newConcurrentMap();
|
this.contexts = Maps.newConcurrentMap();
|
||||||
|
|
||||||
for (String provider : blobstores) {
|
for (String provider : blobstores) {
|
||||||
contexts.put(provider, factory.createContext(provider, wiring, props));
|
contexts.put(provider, BlobStoreContextBuilder.newBuilder(provider)
|
||||||
|
.modules(wiring).overrides(props).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration conf = new ConfigurationBuilder()
|
Configuration conf = new ConfigurationBuilder()
|
||||||
|
@ -113,7 +113,7 @@ public class TweetStoreLiveTest {
|
||||||
ResponseList<Status> statuses = client.getMentions();
|
ResponseList<Status> statuses = client.getMentions();
|
||||||
|
|
||||||
boolean deleted = false;
|
boolean deleted = false;
|
||||||
for (BlobStoreContext context : contexts.values()) {
|
for (BlobStoreContext<?, ?> context : contexts.values()) {
|
||||||
try {
|
try {
|
||||||
if (context.getBlobStore().containerExists(container)) {
|
if (context.getBlobStore().containerExists(container)) {
|
||||||
System.err.printf("deleting container %s at %s%n", container, context.getProviderSpecificContext()
|
System.err.printf("deleting container %s at %s%n", container, context.getProviderSpecificContext()
|
||||||
|
@ -129,7 +129,7 @@ public class TweetStoreLiveTest {
|
||||||
System.err.println("sleeping 60 seconds to allow containers to clear");
|
System.err.println("sleeping 60 seconds to allow containers to clear");
|
||||||
Thread.sleep(60000);
|
Thread.sleep(60000);
|
||||||
}
|
}
|
||||||
for (BlobStoreContext context : contexts.values()) {
|
for (BlobStoreContext<?, ?> context : contexts.values()) {
|
||||||
System.err.printf("creating container %s at %s%n", container, context.getProviderSpecificContext()
|
System.err.printf("creating container %s at %s%n", container, context.getProviderSpecificContext()
|
||||||
.getEndpoint());
|
.getEndpoint());
|
||||||
context.getBlobStore().createContainerInLocation(null, container);
|
context.getBlobStore().createContainerInLocation(null, container);
|
||||||
|
@ -140,7 +140,7 @@ public class TweetStoreLiveTest {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<String, BlobStoreContext> entry : contexts.entrySet()) {
|
for (Entry<String, BlobStoreContext<?, ?>> entry : contexts.entrySet()) {
|
||||||
System.err.printf("filling container %s at %s%n", container, entry.getKey());
|
System.err.printf("filling container %s at %s%n", container, entry.getKey());
|
||||||
controller.addMyTweets(entry.getKey(), statuses);
|
controller.addMyTweets(entry.getKey(), statuses);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ public class TweetStoreLiveTest {
|
||||||
|
|
||||||
System.err.println("sleeping 20 seconds to allow for eventual consistency delay");
|
System.err.println("sleeping 20 seconds to allow for eventual consistency delay");
|
||||||
Thread.sleep(20000);
|
Thread.sleep(20000);
|
||||||
for (BlobStoreContext context : contexts.values()) {
|
for (BlobStoreContext<?, ?> context : contexts.values()) {
|
||||||
assert context.createInputStreamMap(container).size() > 0 : context.getProviderSpecificContext().getEndpoint();
|
assert context.createInputStreamMap(container).size() > 0 : context.getProviderSpecificContext().getEndpoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue