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/06/14 08:35:21 UTC

[03/13] james-project git commit: JAMES-2418 Provide MailRepositoryUrlStore API, contract and memory implementation

JAMES-2418 Provide MailRepositoryUrlStore API, contract and memory implementation


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

Branch: refs/heads/master
Commit: 435a3277012887a0bb9de886acb84497cc22ae1b
Parents: b3d27f8
Author: benwa <bt...@linagora.com>
Authored: Fri Jun 8 11:29:07 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jun 14 15:15:29 2018 +0700

----------------------------------------------------------------------
 server/data/data-api/pom.xml                    |  4 +
 .../api/MailRepositoryUrlStore.java             | 31 +++++++
 .../api/MailRepositoryUrlStoreContract.java     | 86 ++++++++++++++++++++
 server/data/data-memory/pom.xml                 | 24 +++++-
 .../memory/MemoryMailRepositoryUrlStore.java    | 51 ++++++++++++
 .../MemoryMailRepositoryUrlStoreExtension.java  | 38 +++++++++
 .../MemoryMailRepositoryUrlStoreTest.java       | 28 +++++++
 7 files changed, 258 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-api/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-api/pom.xml b/server/data/data-api/pom.xml
index 35a2572..7a58cfc 100644
--- a/server/data/data-api/pom.xml
+++ b/server/data/data-api/pom.xml
@@ -47,6 +47,10 @@
             <artifactId>james-server-mailrepository-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrlStore.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrlStore.java b/server/data/data-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrlStore.java
new file mode 100644
index 0000000..d16232a
--- /dev/null
+++ b/server/data/data-api/src/main/java/org/apache/james/mailrepository/api/MailRepositoryUrlStore.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.mailrepository.api;
+
+import java.util.Set;
+
+public interface MailRepositoryUrlStore {
+
+    void add(MailRepositoryUrl url);
+
+    Set<MailRepositoryUrl> list();
+
+    boolean contains(MailRepositoryUrl url);
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java b/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
new file mode 100644
index 0000000..38b7ee4
--- /dev/null
+++ b/server/data/data-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlStoreContract.java
@@ -0,0 +1,86 @@
+/****************************************************************
+ * 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.mailrepository.api;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.util.concurrency.ConcurrentTestRunner;
+import org.junit.jupiter.api.Test;
+
+public interface MailRepositoryUrlStoreContract {
+    MailRepositoryUrl URL_1 = MailRepositoryUrl.from("proto://var/mail/toto");
+    MailRepositoryUrl URL_2 = MailRepositoryUrl.from("proto://var/mail/tata");
+
+    @Test
+    default void retrieveUsedUrlsShouldBeEmptyByDefault(MailRepositoryUrlStore store) {
+        assertThat(store.list()).isEmpty();
+    }
+
+    @Test
+    default void retrieveUsedUrlsShouldReturnAddedUrl(MailRepositoryUrlStore store) {
+        store.add(URL_1);
+
+        assertThat(store.list()).containsOnly(URL_1);
+    }
+
+    @Test
+    default void retrieveUsedUrlsShouldNotReturnDuplicates(MailRepositoryUrlStore store) {
+        store.add(URL_1);
+        store.add(URL_1);
+
+        assertThat(store.list()).containsOnly(URL_1);
+    }
+
+    @Test
+    default void retrieveUsedUrlsShouldReturnAddedUrls(MailRepositoryUrlStore store) {
+        store.add(URL_1);
+        store.add(URL_2);
+
+        assertThat(store.list()).containsOnly(URL_1, URL_2);
+    }
+
+    @Test
+    default void containsShouldReturnFalseWhenNotExisting(MailRepositoryUrlStore store) {
+        assertThat(store.contains(URL_1)).isFalse();
+    }
+
+    @Test
+    default void containsShouldReturnTrueWhenExisting(MailRepositoryUrlStore store) {
+        store.add(URL_1);
+
+        assertThat(store.contains(URL_1)).isTrue();
+    }
+
+    @Test
+    default void addShouldWorkInConcurrentEnvironment(MailRepositoryUrlStore store) throws Exception {
+        int operationCount = 10;
+        int threadCount = 10;
+        ConcurrentTestRunner testRunner = new ConcurrentTestRunner(threadCount, operationCount,
+            (a, b) -> store.add(MailRepositoryUrl.from("proto://" + a + "/" + b)))
+            .run();
+        testRunner.awaitTermination(1, TimeUnit.MINUTES);
+        testRunner.assertNoException();
+
+        assertThat(store.list()).hasSize(threadCount * operationCount);
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-memory/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-memory/pom.xml b/server/data/data-memory/pom.xml
index 8e14a9e..6b4661b 100644
--- a/server/data/data-memory/pom.xml
+++ b/server/data/data-memory/pom.xml
@@ -39,6 +39,12 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-data-api</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-data-library</artifactId>
         </dependency>
         <dependency>
@@ -69,13 +75,23 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</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>
+            <groupId>org.junit.platform</groupId>
+            <artifactId>junit-platform-launcher</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.vintage</groupId>
+            <artifactId>junit-vintage-engine</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStore.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStore.java b/server/data/data-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStore.java
new file mode 100644
index 0000000..c6ab960
--- /dev/null
+++ b/server/data/data-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStore.java
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.mailrepository.memory;
+
+import java.util.Set;
+
+import org.apache.james.mailrepository.api.MailRepositoryUrl;
+import org.apache.james.mailrepository.api.MailRepositoryUrlStore;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
+public class MemoryMailRepositoryUrlStore implements MailRepositoryUrlStore {
+    private final Set<MailRepositoryUrl> urls;
+
+    public MemoryMailRepositoryUrlStore() {
+        urls = Sets.newConcurrentHashSet();
+    }
+
+    @Override
+    public void add(MailRepositoryUrl url) {
+        urls.add(url);
+    }
+
+    @Override
+    public Set<MailRepositoryUrl> list() {
+        return ImmutableSet.copyOf(urls);
+    }
+
+    @Override
+    public boolean contains(MailRepositoryUrl url) {
+        return urls.contains(url);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreExtension.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreExtension.java b/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreExtension.java
new file mode 100644
index 0000000..bb4cb10
--- /dev/null
+++ b/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreExtension.java
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.mailrepository.memory;
+
+import org.apache.james.mailrepository.api.MailRepositoryUrlStore;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+public class MemoryMailRepositoryUrlStoreExtension implements ParameterResolver {
+    @Override
+    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return (parameterContext.getParameter().getType() == MailRepositoryUrlStore.class);
+    }
+
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return new MemoryMailRepositoryUrlStore();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/435a3277/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreTest.java b/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreTest.java
new file mode 100644
index 0000000..047957f
--- /dev/null
+++ b/server/data/data-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryUrlStoreTest.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.mailrepository.memory;
+
+import org.apache.james.mailrepository.api.MailRepositoryUrlStoreContract;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(MemoryMailRepositoryUrlStoreExtension.class)
+public class MemoryMailRepositoryUrlStoreTest implements MailRepositoryUrlStoreContract {
+
+}


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