mirror of https://github.com/apache/jclouds.git
Fixed code that was broken after the getBlob API change.
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2633 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
befd1f0a4e
commit
c0e08d54ec
|
@ -3,22 +3,17 @@
|
|||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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
|
||||
* 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.
|
||||
* 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.demo.tweetstore.controller;
|
||||
|
|
|
@ -61,7 +61,7 @@ public class StoreTweetsController extends HttpServlet {
|
|||
}
|
||||
|
||||
public Blob apply(Status from) {
|
||||
Blob to = map.newBlob();
|
||||
Blob to = map.newBlob(from.getId() + "");
|
||||
to.getMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
to.getMetadata().setName(from.getId() + "");
|
||||
to.setPayload(from.getText());
|
||||
|
@ -82,7 +82,8 @@ public class StoreTweetsController extends HttpServlet {
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public StoreTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
||||
public StoreTweetsController(
|
||||
Map<String, BlobStoreContext<?, ?>> contexts,
|
||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
||||
TwitterClient client) {
|
||||
this.container = container;
|
||||
|
@ -92,27 +93,27 @@ public class StoreTweetsController extends HttpServlet {
|
|||
|
||||
@VisibleForTesting
|
||||
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
|
||||
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName), "no context for "
|
||||
+ contextName + " in " + contexts.keySet());
|
||||
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName),
|
||||
"no context for " + contextName + " in " + contexts.keySet());
|
||||
BlobMap map = context.createBlobMap(container);
|
||||
for (Status status : allAboutMe) {
|
||||
try {
|
||||
map.put(status.getId() + "", new StatusToBlob(map).apply(status));
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Error storing tweet %s on map %s/%s", status.getId(), context,
|
||||
container);
|
||||
logger.error(e, "Error storing tweet %s on map %s/%s", status.getId(),
|
||||
context, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
if (request.getHeader("X-AppEngine-QueueName") != null
|
||||
&& request.getHeader("X-AppEngine-QueueName").equals("twitter")) {
|
||||
try {
|
||||
String contextName = checkNotNull(request.getHeader("context"),
|
||||
"missing header context");
|
||||
String contextName =
|
||||
checkNotNull(request.getHeader("context"), "missing header context");
|
||||
logger.info("retrieving tweets");
|
||||
addMyTweets(contextName, client.getMyMentions());
|
||||
logger.debug("done storing tweets");
|
||||
|
|
|
@ -54,8 +54,7 @@ public class AddTweetsControllerTest {
|
|||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
||||
.buildContext();
|
||||
context.getAsyncBlobStore().createContainer(container).get();
|
||||
Blob blob = context.getAsyncBlobStore().newBlob();
|
||||
blob.getMetadata().setName("1");
|
||||
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||
blob.setPayload("I love beans!");
|
||||
context.getAsyncBlobStore().putBlob(container, blob).get();
|
||||
|
|
|
@ -50,8 +50,7 @@ public class KeyToStoredTweetStatusTest {
|
|||
|
||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||
BlobMap map = createMap();
|
||||
Blob blob = map.newBlob();
|
||||
blob.getMetadata().setName("1");
|
||||
Blob blob = map.newBlob("1");
|
||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||
blob.setPayload("I love beans!");
|
||||
map.put("1", blob);
|
||||
|
|
|
@ -51,8 +51,7 @@ public class ServiceToStoredTweetStatusesTest {
|
|||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
||||
.buildContext();
|
||||
context.getAsyncBlobStore().createContainer(container).get();
|
||||
Blob blob = context.getAsyncBlobStore().newBlob();
|
||||
blob.getMetadata().setName("1");
|
||||
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||
blob.setPayload("I love beans!");
|
||||
context.getAsyncBlobStore().putBlob(container, blob).get();
|
||||
|
|
Loading…
Reference in New Issue