JAMES-1925 Adding tests for concurrency upon saving mailboxes

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

Branch: refs/heads/master
Commit: 3a8d407fc7a45e91fff538010e49b0218f1797e6
Parents: f653a1f
Author: Benoit Tellier <[email protected]>
Authored: Tue Feb 14 16:34:15 2017 +0700
Committer: Antoine Duprat <[email protected]>
Committed: Wed Feb 15 13:12:39 2017 +0100

----------------------------------------------------------------------
 .../CassandraMailboxMapperConcurrencyTest.java  | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3a8d407f/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
new file mode 100644
index 0000000..b6612be
--- /dev/null
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.mailbox.cassandra.mail;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.apache.james.util.concurrency.ConcurrentTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class CassandraMailboxMapperConcurrencyTest {
+
+    public static final int MAX_RETRY = 10;
+    public static final int UID_VALIDITY = 52;
+    public static final MailboxPath MAILBOX_PATH = new MailboxPath("#private", 
"user", "name");
+    public static final int THREAD_COUNT = 10;
+    public static final int OPERATION_COUNT = 10;
+    private CassandraCluster cassandra;
+    private CassandraMailboxMapper testee;
+
+    @Before
+    public void setUp() {
+        cassandra = CassandraCluster.create(new CassandraModuleComposite(new 
CassandraMailboxModule(), new CassandraAclModule()));
+        cassandra.ensureAllTables();
+
+        CassandraMailboxDAO mailboxDAO = new 
CassandraMailboxDAO(cassandra.getConf(), cassandra.getTypesProvider(), 
MAX_RETRY);
+        CassandraMailboxPathDAO mailboxPathDAO = new 
CassandraMailboxPathDAO(cassandra.getConf(), cassandra.getTypesProvider());
+        testee = new CassandraMailboxMapper(cassandra.getConf(), mailboxDAO, 
mailboxPathDAO, MAX_RETRY);
+    }
+
+    @Test
+    public void saveShouldBeThreadSafe() throws Exception {
+        boolean termination = new ConcurrentTestRunner(THREAD_COUNT, 
OPERATION_COUNT,
+            (a, b) -> testee.save(new SimpleMailbox(MAILBOX_PATH, 
UID_VALIDITY)))
+            .run()
+            .awaitTermination(1, TimeUnit.MINUTES);
+
+        assertThat(termination).isTrue();
+        assertThat(testee.list()).hasSize(1);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to