james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/10] james-project git commit: JAMES-2525 adds createContainer operation to ObjectStorageBlobsDAO
Date Thu, 11 Oct 2018 02:28:46 GMT
JAMES-2525 adds createContainer operation to ObjectStorageBlobsDAO


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

Branch: refs/heads/master
Commit: a2c7e989f662c70eb5d0f46031eba2e2433ed381
Parents: 7c57ae1
Author: Jean Helou <jhe@codamens.fr>
Authored: Tue Sep 11 13:19:38 2018 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Oct 11 09:27:00 2018 +0700

----------------------------------------------------------------------
 .../objectstorage/ObjectStorageBlobsDAO.java    | 13 ++++++++
 .../ObjectStorageBlobsDAOContract.java          |  9 ++----
 .../ObjectStorageBlobsDAOTest.java              | 34 ++++++++++++++++----
 3 files changed, 42 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a2c7e989/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 176e5a4..1e0d12a 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
@@ -33,6 +33,7 @@ import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage;
 import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage;
 import org.jclouds.blobstore.domain.Blob;
 import org.jclouds.blobstore.options.CopyOptions;
+import org.jclouds.domain.Location;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
@@ -41,6 +42,7 @@ 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 final BlobId.Factory blobIdFactory;
@@ -67,6 +69,17 @@ public class ObjectStorageBlobsDAO implements BlobStore {
         return SwiftKeystone3ObjectStorage.daoBuilder(testConfig);
     }
 
+    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());
+            }
+        });
+    }
+
     @Override
     public CompletableFuture<BlobId> save(byte[] data) {
         return save(new ByteArrayInputStream(data));

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2c7e989/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
index a6cb4b4..36501f3 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
@@ -29,22 +29,17 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-
 import org.apache.james.blob.api.BlobId;
-import org.jclouds.blobstore.BlobStore;
-import org.jclouds.domain.Location;
 
-public interface ObjectStorageBlobsDAOContract {
 
-    Location DEFAULT_LOCATION = null;
+public interface ObjectStorageBlobsDAOContract {
 
     ContainerName containerName();
 
     default void assertBlobsDAOCanStoreAndRetrieve(ObjectStorageBlobsDAOBuilder builder)
         throws InterruptedException, ExecutionException, TimeoutException {
-        BlobStore blobStore = builder.getSupplier().get();
-        blobStore.createContainerInLocation(DEFAULT_LOCATION, containerName().value());
         ObjectStorageBlobsDAO dao = builder.build();
+        dao.createContainer(containerName());
         byte[] bytes = "content".getBytes(StandardCharsets.UTF_8);
         CompletableFuture<BlobId> save = dao.save(bytes);
         InputStream inputStream = save.thenApply(dao::read).get(10, TimeUnit.SECONDS);

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2c7e989/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 92eeed1..5dd3cbc 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
@@ -19,12 +19,17 @@
 
 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.junit.jupiter.api.Assertions.fail;
+
 import java.util.UUID;
 
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.BlobStoreContract;
 import org.apache.james.blob.api.HashBlobId;
+import org.apache.james.blob.api.ObjectStoreException;
 import org.apache.james.blob.objectstorage.swift.Credentials;
 import org.apache.james.blob.objectstorage.swift.Identity;
 import org.apache.james.blob.objectstorage.swift.PassHeaderName;
@@ -34,6 +39,7 @@ import org.apache.james.blob.objectstorage.swift.UserHeaderName;
 import org.apache.james.blob.objectstorage.swift.UserName;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerSwiftExtension.class)
@@ -46,6 +52,7 @@ public class ObjectStorageBlobsDAOTest implements BlobStoreContract {
     private ContainerName containerName;
     private org.jclouds.blobstore.BlobStore blobStore;
     private SwiftTempAuthObjectStorage.Configuration testConfig;
+    private ObjectStorageBlobsDAO testee;
 
     @BeforeEach
     void setUp(DockerSwift dockerSwift) throws Exception {
@@ -57,12 +64,14 @@ public class ObjectStorageBlobsDAOTest implements BlobStoreContract {
             .tempAuthHeaderUserName(UserHeaderName.of("X-Storage-User"))
             .tempAuthHeaderPassName(PassHeaderName.of("X-Storage-Pass"))
             .build();
+        BlobId.Factory blobIdFactory = blobIdFactory();
         blobStore = ObjectStorageBlobsDAO
             .builder(testConfig)
             .container(containerName)
-            .blobIdFactory(new HashBlobId.Factory())
+            .blobIdFactory(blobIdFactory)
             .getSupplier().get();
-        blobStore.createContainerInLocation(null, containerName.value());
+        testee = new ObjectStorageBlobsDAO(containerName, blobIdFactory, blobStore);
+        testee.createContainer(containerName);
     }
 
     @AfterEach
@@ -73,16 +82,27 @@ public class ObjectStorageBlobsDAOTest implements BlobStoreContract {
 
     @Override
     public BlobStore testee() {
-        return ObjectStorageBlobsDAO
-            .builder(testConfig)
-            .container(containerName)
-            .blobIdFactory(new HashBlobId.Factory())
-            .build();
+        return testee;
     }
 
     @Override
     public BlobId.Factory blobIdFactory() {
         return new HashBlobId.Factory();
     }
+
+    @Test
+    void canCreateContainer() throws Exception {
+        ContainerName containerName = ContainerName.of(UUID.randomUUID().toString());
+        testee.createContainer(containerName).get();
+        assertThat(blobStore.containerExists(containerName.value())).isTrue();
+    }
+    @Test
+    void failsWithRuntimeExceptionOnCreateContainerTwice() throws Exception {
+        ContainerName containerName = ContainerName.of(UUID.randomUUID().toString());
+        testee.createContainer(containerName).get();
+        assertThatThrownBy(() -> testee.createContainer(containerName).get())
+            .hasCauseInstanceOf(ObjectStoreException.class)
+            .hasMessageContaining("Unable to create container");
+    }
 }
 


---------------------------------------------------------------------
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