You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/01/19 02:19:29 UTC

[05/13] james-project git commit: JAMES-2287 Introduce ObjectStore API

JAMES-2287 Introduce ObjectStore API


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

Branch: refs/heads/master
Commit: 5796a95e297fab53faa8cf5e93203316759cd9d3
Parents: 68e099c
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue Jan 16 13:09:35 2018 +0100
Committer: benwa <bt...@linagora.com>
Committed: Fri Jan 19 09:07:27 2018 +0700

----------------------------------------------------------------------
 pom.xml                                         |  6 ++
 server/blob/blob-api/pom.xml                    | 32 ++++++++
 .../org/apache/james/blob/api/ObjectStore.java  | 28 +++++++
 .../james/blob/api/ObjectStoreContract.java     | 83 ++++++++++++++++++++
 4 files changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5796a95e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index edf90d3..ebe228a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -975,6 +975,12 @@
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
+                <artifactId>blob-api</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
                 <artifactId>blob-cassandra</artifactId>
                 <version>${project.version}</version>
             </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/5796a95e/server/blob/blob-api/pom.xml
----------------------------------------------------------------------
diff --git a/server/blob/blob-api/pom.xml b/server/blob/blob-api/pom.xml
index b0cd9b7..d15765a 100644
--- a/server/blob/blob-api/pom.xml
+++ b/server/blob/blob-api/pom.xml
@@ -33,6 +33,38 @@
     <name>Apache James :: Server :: Blob :: API</name>
 
     <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util-java8</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>nl.jqno.equalsverifier</groupId>
+            <artifactId>equalsverifier</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-launcher</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     
 </project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/5796a95e/server/blob/blob-api/src/main/java/org/apache/james/blob/api/ObjectStore.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/ObjectStore.java b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/ObjectStore.java
new file mode 100644
index 0000000..c2bd88a
--- /dev/null
+++ b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/ObjectStore.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.apache.james.blob.api;
+
+import java.util.concurrent.CompletableFuture;
+
+public interface ObjectStore {
+
+    CompletableFuture<BlobId> save(byte[] data);
+
+    CompletableFuture<byte[]> read(BlobId blobId);
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/5796a95e/server/blob/blob-api/src/test/java/org/apache/james/blob/api/ObjectStoreContract.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/ObjectStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/ObjectStoreContract.java
new file mode 100644
index 0000000..61b5718
--- /dev/null
+++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/ObjectStoreContract.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.apache.james.blob.api;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.jupiter.api.Test;
+
+import com.google.common.base.Strings;
+
+public interface ObjectStoreContract {
+
+    ObjectStore testee();
+    BlobId from(String blodIdAsString);
+
+    @Test
+    default void saveShouldReturnEmptyWhenNullData() throws Exception {
+        assertThatThrownBy(() -> testee().save(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    default void saveShouldSaveEmptyData() throws Exception {
+        BlobId blobId = testee().save(new byte[]{}).join();
+
+        byte[] bytes = testee().read(blobId).join();
+
+        assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty();
+    }
+
+    @Test
+    default void saveShouldReturnBlobId() throws Exception {
+        BlobId blobId = testee().save("toto".getBytes(StandardCharsets.UTF_8)).join();
+
+        assertThat(blobId).isEqualTo(from("31f7a65e315586ac198bd798b6629ce4903d0899476d5741a9f32e2e521b6a66"));
+    }
+
+    @Test
+    default void readShouldBeEmptyWhenNoExisting() throws IOException {
+        byte[] bytes = testee().read(from("unknown")).join();
+
+        assertThat(bytes).isEmpty();
+    }
+
+    @Test
+    default void readShouldReturnSavedData() throws IOException {
+        BlobId blobId = testee().save("toto".getBytes(StandardCharsets.UTF_8)).join();
+
+        byte[] bytes = testee().read(blobId).join();
+
+        assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("toto");
+    }
+
+    @Test
+    default void readShouldReturnLongSavedData() throws IOException {
+        String longString = Strings.repeat("0123456789\n", 1000);
+        BlobId blobId = testee().save(longString.getBytes(StandardCharsets.UTF_8)).join();
+
+        byte[] bytes = testee().read(blobId).join();
+
+        assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo(longString);
+    }
+}


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