james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [19/21] james-project git commit: JAMES-2047 Ensure JMAP mailbox provisioning do not fail on concurrent runs
Date Wed, 07 Jun 2017 10:46:29 GMT
JAMES-2047 Ensure JMAP mailbox provisioning do not fail on concurrent runs


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

Branch: refs/heads/master
Commit: 8357286255bf921bf49b6b78295e24e1d0b9d6ad
Parents: 0456601
Author: benwa <btellier@linagora.com>
Authored: Tue Jun 6 11:20:32 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jun 7 17:40:00 2017 +0700

----------------------------------------------------------------------
 .../DefaultMailboxesProvisioningFilter.java     |  3 +
 .../DefaultMailboxesProvisioningFilterTest.java | 84 ++++++++++++++++++++
 2 files changed, 87 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/83572862/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
index 0089ff2..e405604 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.metrics.api.TimeMetric;
@@ -102,6 +103,8 @@ public class DefaultMailboxesProvisioningFilter implements Filter {
     private void createMailbox(MailboxPath mailboxPath, MailboxSession session) {
         try {
             mailboxManager.createMailbox(mailboxPath, session);
+        } catch (MailboxExistsException e) {
+            LOGGER.info("Mailbox {} have been created concurrently", mailboxPath);
         } catch (MailboxException e) {
             throw Throwables.propagate(e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/83572862/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
new file mode 100644
index 0000000..e706d27
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilterTest.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.jmap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.util.concurrency.ConcurrentTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.steveash.guavate.Guavate;
+
+public class DefaultMailboxesProvisioningFilterTest {
+
+    public static final String USERNAME = "username";
+    private DefaultMailboxesProvisioningFilter testee;
+    private MailboxSession session;
+    private MailboxManager mailboxManager;
+
+    @Before
+    public void before() throws Exception {
+        session = new MockMailboxSession(USERNAME);
+
+        InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources();
+        mailboxManager = inMemoryIntegrationResources.createMailboxManager(new SimpleGroupMembershipResolver());
+        testee = new DefaultMailboxesProvisioningFilter(mailboxManager, new NoopMetricFactory());
+    }
+
+    @Test
+    public void createMailboxesIfNeededShouldCreateSystemMailboxes() throws Exception {
+        testee.createMailboxesIfNeeded(session);
+
+        assertThat(mailboxManager.list(session))
+            .containsOnlyElementsOf(DefaultMailboxes.DEFAULT_MAILBOXES
+                .stream()
+                .map(mailboxName -> new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME,
mailboxName))
+                .collect(Guavate.toImmutableList()));
+    }
+
+    @Test
+    public void createMailboxesIfNeededShouldNotGenerateExceptionsInConcurrentEnvironment()
throws Exception {
+        int threadCount = 10;
+        int operationCount = 1;
+        new ConcurrentTestRunner(threadCount, operationCount,
+            (threadNumber, step) -> testee.createMailboxesIfNeeded(session))
+            .run()
+            .assertNoException()
+            .awaitTermination(10, TimeUnit.SECONDS);
+
+        assertThat(mailboxManager.list(session))
+            .containsOnlyElementsOf(DefaultMailboxes.DEFAULT_MAILBOXES
+                .stream()
+                .map(mailboxName -> new MailboxPath(MailboxConstants.USER_NAMESPACE, USERNAME,
mailboxName))
+                .collect(Guavate.toImmutableList()));
+    }
+
+}
+


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