mirror of https://github.com/apache/jclouds.git
Using the new context view (see http://code.google.com/p/jclouds/issues/detail?id=904) in gae-tweetstore-spring
This commit is contained in:
parent
a1c26e5701
commit
507a929f72
|
@ -42,8 +42,8 @@ import javax.servlet.Servlet;
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.demo.tweetstore.config.util.CredentialsCollector;
|
import org.jclouds.demo.tweetstore.config.util.CredentialsCollector;
|
||||||
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.controller.EnqueueStoresController;
|
import org.jclouds.demo.tweetstore.controller.EnqueueStoresController;
|
||||||
|
@ -86,7 +86,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
|
|
||||||
private ServletConfig servletConfig;
|
private ServletConfig servletConfig;
|
||||||
|
|
||||||
private Map<String, BlobStoreContext<?, ?>> providerTypeToBlobStoreMap;
|
private Map<String, BlobStoreContext> providerTypeToBlobStoreMap;
|
||||||
private Twitter twitterClient;
|
private Twitter twitterClient;
|
||||||
private String container;
|
private String container;
|
||||||
private Queue queue;
|
private Queue queue;
|
||||||
|
@ -116,8 +116,8 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
// 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, BlobStoreContextBuilder
|
providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint)
|
||||||
.newBuilder(hint).modules(modules).overrides(props).build());
|
.modules(modules).overrides(props).build(BlobStoreContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a queue for submitting store tweet requests
|
// get a queue for submitting store tweet requests
|
||||||
|
@ -211,7 +211,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
LOGGER.trace("About to close contexts.");
|
LOGGER.trace("About to close contexts.");
|
||||||
for (BlobStoreContext<?, ?> context : providerTypeToBlobStoreMap.values()) {
|
for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
LOGGER.trace("Contexts closed.");
|
LOGGER.trace("Contexts closed.");
|
||||||
|
|
|
@ -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
|
||||||
public AddTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
public AddTweetsController(Map<String, BlobStoreContext> contexts,
|
||||||
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
ServiceToStoredTweetStatuses blobStoreContextToContainerResult) {
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class EnqueueStoresController extends HttpServlet {
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public EnqueueStoresController(Map<String, BlobStoreContext<?, ?>> contexts,
|
public EnqueueStoresController(Map<String, BlobStoreContext> contexts,
|
||||||
Queue taskQueue) {
|
Queue taskQueue) {
|
||||||
contextNames = contexts.keySet();
|
contextNames = contexts.keySet();
|
||||||
this.taskQueue = taskQueue;
|
this.taskQueue = taskQueue;
|
||||||
|
|
|
@ -73,7 +73,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;
|
||||||
|
|
||||||
|
@ -82,7 +82,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;
|
||||||
|
@ -91,7 +91,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) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.demo.tweetstore.functions;
|
package org.jclouds.demo.tweetstore.functions;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -27,6 +28,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.Context;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
import org.jclouds.demo.tweetstore.domain.StoredTweetStatus;
|
||||||
|
@ -39,11 +41,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,8 +55,8 @@ 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 = URI.create(context.unwrap(Context.class).getProviderMetadata().getEndpoint()).getHost();
|
||||||
try {
|
try {
|
||||||
BlobMap blobMap = context.createBlobMap(container);
|
BlobMap blobMap = context.createBlobMap(container);
|
||||||
Set<String> blobs = blobMap.keySet();
|
Set<String> blobs = blobMap.keySet();
|
||||||
|
|
|
@ -25,8 +25,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.TransientApiMetadata;
|
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;
|
||||||
|
@ -46,12 +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();
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext<?, ?> context = BlobStoreContextBuilder.newBuilder(transientApiMetadata).build();
|
BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class);
|
||||||
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");
|
||||||
|
@ -64,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);
|
||||||
|
|
|
@ -26,8 +26,8 @@ import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.TransientApiMetadata;
|
import org.jclouds.blobstore.TransientApiMetadata;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -43,16 +43,16 @@ import com.google.common.collect.ImmutableMap;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class EnqueueStoresControllerTest {
|
public class EnqueueStoresControllerTest {
|
||||||
|
|
||||||
Map<String, BlobStoreContext<?, ?>> createBlobStores() {
|
Map<String, BlobStoreContext> createBlobStores() {
|
||||||
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap.<String, BlobStoreContext<?, ?>>of(
|
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext>of(
|
||||||
"test1", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build(),
|
"test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class),
|
||||||
"test2", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build());
|
"test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class));
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnqueueStores() {
|
public void testEnqueueStores() {
|
||||||
Map<String, BlobStoreContext<?, ?>> stores = createBlobStores();
|
Map<String, BlobStoreContext> stores = createBlobStores();
|
||||||
Queue taskQueue = createMock(Queue.class);
|
Queue taskQueue = createMock(Queue.class);
|
||||||
EnqueueStoresController function = new EnqueueStoresController(stores, taskQueue);
|
EnqueueStoresController function = new EnqueueStoresController(stores, taskQueue);
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.TransientApiMetadata;
|
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;
|
||||||
|
@ -57,19 +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 {
|
||||||
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
Map<String, BlobStoreContext<?, ?>> contexts = ImmutableMap.<String, BlobStoreContext<?, ?>>of(
|
Map<String, BlobStoreContext> contexts = ImmutableMap.<String, BlobStoreContext>of(
|
||||||
"test1", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build(),
|
"test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class),
|
||||||
"test2", BlobStoreContextBuilder.newBuilder(transientApiMetadata).build());
|
"test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class));
|
||||||
for (BlobStoreContext<?, ?> blobstore : contexts.values()) {
|
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);
|
||||||
|
@ -101,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");
|
||||||
|
|
|
@ -23,9 +23,9 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.TransientApiMetadata;
|
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;
|
||||||
|
@ -41,8 +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 =
|
BlobStoreContext context =
|
||||||
BlobStoreContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build();
|
ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class);
|
||||||
context.getBlobStore().createContainerInLocation(null, "test1");
|
context.getBlobStore().createContainerInLocation(null, "test1");
|
||||||
return context.createBlobMap("test1");
|
return context.createBlobMap("test1");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.blobstore.TransientApiMetadata;
|
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;
|
||||||
|
@ -43,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();
|
TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build();
|
||||||
for (String name : new String[] { "1", "2" }) {
|
for (String name : new String[] { "1", "2" }) {
|
||||||
BlobStoreContext<?, ?> context = BlobStoreContextBuilder.newBuilder(transientApiMetadata).build();
|
BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class);
|
||||||
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");
|
||||||
|
@ -61,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);
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,9 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import org.jclouds.Context;
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
|
||||||
import org.jclouds.demo.tweetstore.config.SpringServletConfig;
|
import org.jclouds.demo.tweetstore.config.SpringServletConfig;
|
||||||
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;
|
||||||
|
@ -73,7 +74,7 @@ public class TweetStoreLiveTest {
|
||||||
|
|
||||||
GoogleDevServer server;
|
GoogleDevServer 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 =
|
||||||
|
@ -100,8 +101,8 @@ public class TweetStoreLiveTest {
|
||||||
this.contexts = Maps.newConcurrentMap();
|
this.contexts = Maps.newConcurrentMap();
|
||||||
|
|
||||||
for (String provider : blobstores) {
|
for (String provider : blobstores) {
|
||||||
contexts.put(provider, BlobStoreContextBuilder.newBuilder(provider)
|
contexts.put(provider, ContextBuilder.newBuilder(provider)
|
||||||
.modules(wiring).overrides(props).build());
|
.modules(wiring).overrides(props).build(BlobStoreContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration conf = new ConfigurationBuilder()
|
Configuration conf = new ConfigurationBuilder()
|
||||||
|
@ -116,10 +117,10 @@ 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()) {
|
||||||
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,
|
||||||
.getEndpoint());
|
context.unwrap(Context.class).getProviderMetadata().getEndpoint());
|
||||||
context.getBlobStore().deleteContainer(container);
|
context.getBlobStore().deleteContainer(container);
|
||||||
deleted = true;
|
deleted = true;
|
||||||
}
|
}
|
||||||
|
@ -128,9 +129,9 @@ 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,
|
||||||
.getEndpoint());
|
context.unwrap(Context.class).getProviderMetadata().getEndpoint());
|
||||||
context.getBlobStore().createContainerInLocation(null, container);
|
context.getBlobStore().createContainerInLocation(null, container);
|
||||||
}
|
}
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
|
@ -138,7 +139,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);
|
||||||
}
|
}
|
||||||
|
@ -205,8 +206,8 @@ 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.unwrap(Context.class).getProviderMetadata().getEndpoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue