james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/7] james-project git commit: JAMES-2589 Avoid failing when the container already exist
Date Mon, 26 Nov 2018 09:41:27 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 211b3f1cf -> 92a41825d


JAMES-2589 Avoid failing when the container already exist

This is for instance the case when you reboot James.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/744c9893
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/744c9893
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/744c9893

Branch: refs/heads/master
Commit: 744c98935a23aba6e8c9f1ee6a57bcb84b0646f9
Parents: 211b3f1
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Nov 22 15:40:32 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Mon Nov 26 16:39:11 2018 +0700

----------------------------------------------------------------------
 .../james/blob/objectstorage/ObjectStorageBlobsDAO.java | 12 +++++++-----
 .../blob/objectstorage/ObjectStorageBlobsDAOTest.java   | 11 +++++------
 2 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/744c9893/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
index 5a1cc62..ea71d10 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
@@ -35,6 +35,8 @@ import org.jclouds.blobstore.domain.Blob;
 import org.jclouds.blobstore.options.CopyOptions;
 import org.jclouds.domain.Location;
 import org.jclouds.io.Payload;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
@@ -44,7 +46,8 @@ import com.google.common.hash.HashingInputStream;
 
 public class ObjectStorageBlobsDAO implements BlobStore {
     private static final InputStream EMPTY_STREAM = new ByteArrayInputStream(new byte[0]);
-    public static final Location DEFAULT_LOCATION = null;
+    private static final Location DEFAULT_LOCATION = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ObjectStorageBlobsDAO.class);
 
 
     private final BlobId.Factory blobIdFactory;
@@ -76,11 +79,10 @@ public class ObjectStorageBlobsDAO implements BlobStore {
     public CompletableFuture<ContainerName> createContainer(ContainerName name) {
         return CompletableFuture.supplyAsync(() -> blobStore.createContainerInLocation(DEFAULT_LOCATION,
name.value()))
             .thenApply(created -> {
-                if (created) {
-                    return name;
-                } else {
-                    throw new ObjectStoreException("Unable to create container " + name.value());
+                if (!created) {
+                    LOGGER.debug("{} already existed", name);
                 }
+                return name;
             });
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/744c9893/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
index c5deef5..265bc9f 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
@@ -20,7 +20,7 @@
 package org.apache.james.blob.objectstorage;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.assertThatCode;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -33,7 +33,6 @@ import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.blob.api.MetricableBlobStoreContract;
-import org.apache.james.blob.api.ObjectStoreException;
 import org.apache.james.blob.objectstorage.crypto.CryptoConfig;
 import org.apache.james.blob.objectstorage.swift.Credentials;
 import org.apache.james.blob.objectstorage.swift.Identity;
@@ -110,12 +109,12 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract
{
     }
 
     @Test
-    void createContainerShouldFailWithRuntimeExceptionWhenCreateContainerTwice() throws Exception
{
+    void createContainerShouldNotFailWithRuntimeExceptionWhenCreateContainerTwice() throws
Exception {
         ContainerName containerName = ContainerName.of(UUID.randomUUID().toString());
+
         objectStorageBlobsDAO.createContainer(containerName).get();
-        assertThatThrownBy(() -> objectStorageBlobsDAO.createContainer(containerName).get())
-            .hasCauseInstanceOf(ObjectStoreException.class)
-            .hasMessageContaining("Unable to create container");
+        assertThatCode(() -> objectStorageBlobsDAO.createContainer(containerName).get())
+            .doesNotThrowAnyException();
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message