diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java index 4836f3d5d4..a179998e1c 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientAsyncBlobStore.java @@ -360,11 +360,12 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore { */ @Override public ListenableFuture createContainerInLocation(final Location location, final String name) { - if (!getContainerToBlobs().containsKey(name)) { - getContainerToBlobs().put(name, new ConcurrentHashMap()); - getContainerToLocation().put(name, location != null ? location : defaultLocation.get()); + if (getContainerToBlobs().containsKey(name)) { + return immediateFuture(Boolean.FALSE); } - return immediateFuture(getContainerToBlobs().containsKey(name)); + getContainerToBlobs().put(name, new ConcurrentHashMap()); + getContainerToLocation().put(name, location != null ? location : defaultLocation.get()); + return immediateFuture(Boolean.TRUE); } /** diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java index ec98bf2603..2a6fdc0123 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/TransientContainerIntegrationTest.java @@ -21,14 +21,18 @@ package org.jclouds.blobstore.integration; import static com.google.common.collect.Iterables.getOnlyElement; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; import javax.ws.rs.core.MediaType; +import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest; +import org.jclouds.domain.Location; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -65,4 +69,18 @@ public class TransientContainerIntegrationTest extends BaseContainerIntegrationT returnContainer(containerName); } } -} \ No newline at end of file + + @Test(groups = { "integration", "live" }) + public void testDuplicateCreateContainer() { + BlobStore blobStore = context.getBlobStore(); + Location location = null; + String container = "container"; + boolean created; + + created = blobStore.createContainerInLocation(location, container); + assertTrue(created); + + created = blobStore.createContainerInLocation(location, container); + assertFalse(created); + } +}