From eefd7d47f84a661fbc5d190331a05c24e630ee85 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Wed, 14 Oct 2009 21:24:50 +0000 Subject: [PATCH] removed multimap for user metadata git-svn-id: http://jclouds.googlecode.com/svn/trunk@1984 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../storage/blob/AzureBlobConnection.java | 9 +- .../storage/blob/AzureBlobConnectionTest.java | 11 +- .../internal/StubAzureBlobConnection.java | 5 +- .../RestAzureStorageConnectionModuleTest.java | 109 ++++++++++++++++++ ...x.java => BindMapToHeadersWithPrefix.java} | 11 +- .../cloudfiles/CloudFilesConnection.java | 7 +- .../CloudFilesConnectionLiveTest.java | 6 +- .../internal/StubCloudFilesConnection.java | 5 +- 8 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 azure/storage/core/src/test/java/org/jclouds/azure/storage/config/RestAzureStorageConnectionModuleTest.java rename blobstore/core/src/main/java/org/jclouds/blobstore/binders/{BindMultimapToHeadersWithPrefix.java => BindMapToHeadersWithPrefix.java} (83%) diff --git a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobConnection.java b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobConnection.java index c6e49d8a2a..09207f8f68 100644 --- a/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobConnection.java +++ b/azure/storage/blob/core/src/main/java/org/jclouds/azure/storage/blob/AzureBlobConnection.java @@ -23,6 +23,7 @@ */ package org.jclouds.azure.storage.blob; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -51,7 +52,7 @@ import org.jclouds.azure.storage.filters.SharedKeyAuthentication; import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.azure.storage.reference.AzureStorageHeaders; import org.jclouds.blobstore.binders.BindBlobToEntity; -import org.jclouds.blobstore.binders.BindMultimapToHeadersWithPrefix; +import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix; import org.jclouds.blobstore.functions.BlobKey; import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; @@ -69,8 +70,6 @@ import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.XMLResponseParser; -import com.google.common.collect.Multimap; - /** * Provides access to Azure Blob via their REST API. *

@@ -144,7 +143,7 @@ public interface AzureBlobConnection { @Path("{container}") @QueryParams(keys = { "restype", "comp" }, values = { "container", "metadata" }) void setContainerMetadata(@PathParam("container") String container, - @BinderParam(BindMultimapToHeadersWithPrefix.class) Multimap metadata); + @BinderParam(BindMapToHeadersWithPrefix.class) Map metadata); /** * The Delete Container operation marks the specified container for deletion. The container and @@ -302,7 +301,7 @@ public interface AzureBlobConnection { @Path("{container}/{key}") @QueryParams(keys = { "comp" }, values = { "metadata" }) void setBlobMetadata(@PathParam("container") String container, @PathParam("key") String key, - @BinderParam(BindMultimapToHeadersWithPrefix.class) Multimap metadata); + @BinderParam(BindMapToHeadersWithPrefix.class) Map metadata); /** * The Delete Blob operation marks the specified blob for deletion. The blob is later deleted diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java index 9db6f505a6..6cb496122c 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/AzureBlobConnectionTest.java @@ -31,6 +31,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; import java.util.Collections; +import java.util.Map; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.HttpHeaders; @@ -62,8 +63,8 @@ import org.jclouds.util.Jsr330; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -301,10 +302,10 @@ public class AzureBlobConnectionTest { public void testSetContainerMetadata() throws SecurityException, NoSuchMethodException { Method method = AzureBlobConnection.class.getMethod("setContainerMetadata", String.class, - Multimap.class); + Map.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { "container", ImmutableMultimap.of("key", "value") }); + new Object[] { "container", ImmutableMap.of("key", "value") }); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net"); assertEquals(httpMethod.getEndpoint().getPath(), "/container"); assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=metadata"); @@ -323,9 +324,9 @@ public class AzureBlobConnectionTest { public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException { Method method = AzureBlobConnection.class.getMethod("setBlobMetadata", String.class, - String.class, Multimap.class); + String.class, Map.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, - new Object[] { "container", "blob", ImmutableMultimap.of("key", "value") }); + new Object[] { "container", "blob", ImmutableMap.of("key", "value") }); assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net"); assertEquals(httpMethod.getEndpoint().getPath(), "/container/blob"); assertEquals(httpMethod.getEndpoint().getQuery(), "comp=metadata"); diff --git a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobConnection.java b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobConnection.java index 37f1f745d5..f375a22c0c 100644 --- a/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobConnection.java +++ b/azure/storage/blob/core/src/test/java/org/jclouds/azure/storage/blob/internal/StubAzureBlobConnection.java @@ -50,7 +50,6 @@ import org.jclouds.util.DateService; import com.google.common.base.Function; import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; import com.google.common.collect.Sets; /** @@ -128,11 +127,11 @@ public class StubAzureBlobConnection extends StubBlobStore metadata) { + public void setContainerMetadata(String container, Map metadata) { throw new UnsupportedOperationException(); } - public void setBlobMetadata(String container, String key, Multimap metadata) { + public void setBlobMetadata(String container, String key, Map metadata) { throw new UnsupportedOperationException(); } } diff --git a/azure/storage/core/src/test/java/org/jclouds/azure/storage/config/RestAzureStorageConnectionModuleTest.java b/azure/storage/core/src/test/java/org/jclouds/azure/storage/config/RestAzureStorageConnectionModuleTest.java new file mode 100644 index 0000000000..26d502965f --- /dev/null +++ b/azure/storage/core/src/test/java/org/jclouds/azure/storage/config/RestAzureStorageConnectionModuleTest.java @@ -0,0 +1,109 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.azure.storage.config; + +import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT; +import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY; +import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +import java.util.concurrent.ConcurrentMap; + +import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent; +import org.jclouds.http.HttpRetryHandler; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.http.handlers.DelegatingErrorHandler; +import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.http.handlers.RedirectionRetryHandler; +import org.jclouds.util.DateService; +import org.jclouds.util.Jsr330; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "azure.RestAzureStorageConnectionModuleTest") +public class RestAzureStorageConnectionModuleTest { + + Injector createInjector() { + return Guice.createInjector(new RestAzureStorageConnectionModule(), new ParserModule(), + new AbstractModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Jsr330.named(PROPERTY_AZURESTORAGE_ACCOUNT)).to( + "user"); + bindConstant().annotatedWith(Jsr330.named(PROPERTY_AZURESTORAGE_KEY)).to( + "secret"); + bindConstant().annotatedWith( + Jsr330.named(PROPERTY_AZURESTORAGE_SESSIONINTERVAL)).to("2"); + } + }); + } + + @Test + void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException { + RestAzureStorageConnectionModule module = new RestAzureStorageConnectionModule(); + + ConcurrentMap map = module.provideTimeStampCache(1, new DateService()); + String timeStamp = map.get("foo"); + for (int i = 0; i < 10; i++) + map.get("foo"); + assertEquals(timeStamp, map.get("foo")); + Thread.sleep(1001); + assertFalse(timeStamp.equals(map.get("foo"))); + } + + @Test + void testServerErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getServerErrorHandler().getClass(), + ParseAzureStorageErrorFromXmlContent.class); + } + + @Test + void testClientErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getClientErrorHandler().getClass(), + ParseAzureStorageErrorFromXmlContent.class); + } + + @Test + void testClientRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY); + } + + @Test + void testRedirectionRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getRedirectionRetryHandler().getClass(), + RedirectionRetryHandler.class); + } + +} \ No newline at end of file diff --git a/blobstore/core/src/main/java/org/jclouds/blobstore/binders/BindMultimapToHeadersWithPrefix.java b/blobstore/core/src/main/java/org/jclouds/blobstore/binders/BindMapToHeadersWithPrefix.java similarity index 83% rename from blobstore/core/src/main/java/org/jclouds/blobstore/binders/BindMultimapToHeadersWithPrefix.java rename to blobstore/core/src/main/java/org/jclouds/blobstore/binders/BindMapToHeadersWithPrefix.java index 29c83d53e4..6172cffa52 100644 --- a/blobstore/core/src/main/java/org/jclouds/blobstore/binders/BindMultimapToHeadersWithPrefix.java +++ b/blobstore/core/src/main/java/org/jclouds/blobstore/binders/BindMapToHeadersWithPrefix.java @@ -25,6 +25,7 @@ package org.jclouds.blobstore.binders; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; +import java.util.Map; import java.util.Map.Entry; import javax.inject.Inject; @@ -33,20 +34,18 @@ import javax.inject.Named; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; -import com.google.common.collect.Multimap; - -public class BindMultimapToHeadersWithPrefix implements Binder { +public class BindMapToHeadersWithPrefix implements Binder { private final String metadataPrefix; @Inject - public BindMultimapToHeadersWithPrefix(@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) { + public BindMapToHeadersWithPrefix(@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) { this.metadataPrefix = metadataPrefix; } @SuppressWarnings("unchecked") public void bindToRequest(HttpRequest request, Object entity) { - Multimap userMetadata = (Multimap) entity; - for (Entry entry : userMetadata.entries()) { + Map userMetadata = (Map) entity; + for (Entry entry : userMetadata.entrySet()) { if (entry.getKey().startsWith(metadataPrefix)) { request.getHeaders().put(entry.getKey().toLowerCase(), entry.getValue()); } else { diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnection.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnection.java index 1f37f1e8c6..50e811a2ed 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnection.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnection.java @@ -23,6 +23,7 @@ */ package org.jclouds.rackspace.cloudfiles; +import java.util.Map; import java.util.SortedSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -37,7 +38,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import org.jclouds.blobstore.binders.BindBlobToEntity; -import org.jclouds.blobstore.binders.BindMultimapToHeadersWithPrefix; +import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.functions.BlobKey; @@ -74,8 +75,6 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; -import com.google.common.collect.Multimap; - /** * Provides access to Cloud Files via their REST API. *

@@ -142,7 +141,7 @@ public interface CloudFilesConnection { boolean setObjectMetadata( @PathParam("container") String container, @PathParam("key") String key, - @BinderParam(BindMultimapToHeadersWithPrefix.class) Multimap userMetadata); + @BinderParam(BindMapToHeadersWithPrefix.class) Map userMetadata); @GET @ResponseParser(ParseContainerCDNMetadataListFromGsonResponse.class) diff --git a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnectionLiveTest.java b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnectionLiveTest.java index 60d86b02fb..a875bb898c 100644 --- a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnectionLiveTest.java +++ b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/CloudFilesConnectionLiveTest.java @@ -30,6 +30,7 @@ import static org.testng.Assert.fail; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.Map; import java.util.SortedSet; import java.util.concurrent.TimeUnit; @@ -52,9 +53,8 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.google.common.collect.HashMultimap; import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; +import com.google.common.collect.Maps; /** * Tests behavior of {@code JaxrsAnnotationProcessor} @@ -307,7 +307,7 @@ public class CloudFilesConnectionLiveTest { assertEquals(metadata.getUserMetadata().get("metadata"), "metadata-value"); // // Test POST to update object's metadata - Multimap userMetadata = HashMultimap.create(); + Map userMetadata = Maps.newHashMap(); userMetadata.put("New-Metadata-1", "value-1"); userMetadata.put("New-Metadata-2", "value-2"); assertTrue(connection.setObjectMetadata(containerName, object.getKey(), userMetadata)); diff --git a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesConnection.java b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesConnection.java index a5ea41a2e4..a4974ac656 100644 --- a/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesConnection.java +++ b/rackspace/cloudfiles/core/src/test/java/org/jclouds/rackspace/cloudfiles/internal/StubCloudFilesConnection.java @@ -43,8 +43,6 @@ import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions; import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions; import org.jclouds.util.DateService; -import com.google.common.collect.Multimap; - /** * Implementation of {@link CloudFilesBlobStore} which keeps all data in a local Map object. * @@ -71,8 +69,7 @@ public class StubCloudFilesConnection extends throw new UnsupportedOperationException(); } - public boolean setObjectMetadata(String container, String key, - Multimap userMetadata) { + public boolean setObjectMetadata(String container, String key, Map userMetadata) { throw new UnsupportedOperationException(); }