JAMES-1925 IT testing for create mailbox concurrency

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

Branch: refs/heads/master
Commit: f653a1f210e1455b7979964e2453148b3ad8df1f
Parents: 0063d30
Author: Quynh Nguyen <[email protected]>
Authored: Mon Feb 13 14:46:25 2017 +0700
Committer: Antoine Duprat <[email protected]>
Committed: Wed Feb 15 13:12:39 2017 +0100

----------------------------------------------------------------------
 ...ssandraUserProvisionningConcurrencyTest.java |  36 +++++++
 .../jmap/UserProvisionningConcurrencyTest.java  | 108 +++++++++++++++++++
 .../MemoryUserProvisionningConcurrencyTest.java |  35 ++++++
 3 files changed, 179 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f653a1f2/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraUserProvisionningConcurrencyTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraUserProvisionningConcurrencyTest.java
 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraUserProvisionningConcurrencyTest.java
new file mode 100644
index 0000000..efd5be7
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraUserProvisionningConcurrencyTest.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.cassandra;
+
+import org.apache.james.CassandraJmapTestRule;
+import org.apache.james.JmapJamesServer;
+import org.apache.james.jmap.UserProvisionningConcurrencyTest;
+import org.junit.Rule;
+
+public class CassandraUserProvisionningConcurrencyTest extends 
UserProvisionningConcurrencyTest {
+    @Rule
+    public CassandraJmapTestRule rule = 
CassandraJmapTestRule.defaultTestRule();
+
+    @Override
+    protected JmapJamesServer createJmapServer() {
+        return rule.jmapServer();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f653a1f2/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/UserProvisionningConcurrencyTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/UserProvisionningConcurrencyTest.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/UserProvisionningConcurrencyTest.java
new file mode 100644
index 0000000..643500d
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/UserProvisionningConcurrencyTest.java
@@ -0,0 +1,108 @@
+/****************************************************************
+ * 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 com.jayway.restassured.RestAssured.given;
+import static com.jayway.restassured.RestAssured.with;
+import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.james.JmapJamesServer;
+import org.apache.james.util.concurrency.ConcurrentTestRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+
+public abstract class UserProvisionningConcurrencyTest {
+    private static final String NAME = "[0][0]";
+    private static final String ARGUMENTS = "[0][1]";
+    private static final String DOMAIN = "mydomain.tld";
+    private static final String USER = "myuser@" + DOMAIN;
+    private static final String PASSWORD = "secret";
+    protected abstract JmapJamesServer createJmapServer();
+
+    private JmapJamesServer jmapServer;
+
+    @Before
+    public void setup() throws Throwable {
+        jmapServer = createJmapServer();
+        jmapServer.start();
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+            
.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
+            .setPort(jmapServer.getJmapProbe()
+                .getJmapPort())
+            .build();
+
+        jmapServer.serverProbe().addDomain(DOMAIN);
+        jmapServer.serverProbe().addUser(USER, PASSWORD);
+    }
+
+    @After
+    public void teardown() {
+        jmapServer.stop();
+    }
+
+    @Test
+    public void provisionMailboxesShouldNotDuplicateMailboxByName() throws 
Exception {
+        String token = HttpJmapAuthentication.authenticateJamesUser(baseUri(), 
USER, PASSWORD).serialize();
+
+        boolean termination = new ConcurrentTestRunner(10, 1,
+            (a, b) -> with()
+                .header("Authorization", token)
+                .body("[[\"getMailboxes\", {}, \"#0\"]]")
+                .post("/jmap"))
+            .run()
+            .awaitTermination(1, TimeUnit.MINUTES);
+
+        assertThat(termination).isTrue();
+
+        given()
+            .header("Authorization", token)
+            .body("[[\"getMailboxes\", {}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("mailboxes"))
+            .body(ARGUMENTS + ".list", hasSize(5))
+            .body(ARGUMENTS + ".list.name", 
hasItems(DefaultMailboxes.DEFAULT_MAILBOXES.toArray()));
+
+    }
+
+    private URIBuilder baseUri() {
+        return new URIBuilder()
+            .setScheme("http")
+            .setHost("localhost")
+            .setPort(jmapServer.getJmapProbe()
+                .getJmapPort())
+            .setCharset(Charsets.UTF_8);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f653a1f2/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryUserProvisionningConcurrencyTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryUserProvisionningConcurrencyTest.java
 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryUserProvisionningConcurrencyTest.java
new file mode 100644
index 0000000..056d4e7
--- /dev/null
+++ 
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryUserProvisionningConcurrencyTest.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.memory;
+
+import org.apache.james.JmapJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.jmap.UserProvisionningConcurrencyTest;
+import org.junit.Rule;
+
+public class MemoryUserProvisionningConcurrencyTest extends 
UserProvisionningConcurrencyTest {
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+
+    @Override
+    protected JmapJamesServer createJmapServer() {
+        return memoryJmap.jmapServer();
+    }
+}


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

Reply via email to