james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r940288 - in /james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional: AbstractStressTest.java jcr/JCRStressTest.java jpa/JPAStressTest.java
Date Sun, 02 May 2010 18:26:33 GMT
Author: norman
Date: Sun May  2 18:26:33 2010
New Revision: 940288

URL: http://svn.apache.org/viewvc?rev=940288&view=rev
Log:
Add Stress test for JCR which shows it fails on heavy load :/

Added:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/AbstractStressTest.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java
Modified:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java

Added: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/AbstractStressTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/AbstractStressTest.java?rev=940288&view=auto
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/AbstractStressTest.java
(added)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/AbstractStressTest.java
Sun May  2 18:26:33 2010
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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.imap.functional;
+
+import java.io.ByteArrayInputStream;
+import java.util.Date;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.mail.Flags;
+
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.imap.mailbox.Mailbox;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.StoreMailboxManager;
+import org.junit.Test;
+
+public abstract class AbstractStressTest {
+
+    protected abstract StoreMailboxManager<?> getMailboxManager();
+    
+    @Test
+    public void testStessTest() throws InterruptedException, MailboxException {
+       
+        final CountDownLatch latch = new CountDownLatch(1000);
+        final ExecutorService pool = Executors.newFixedThreadPool(500);
+        
+        MailboxSession session = getMailboxManager().createSystemSession("test", new SimpleLog("Test"));
+        getMailboxManager().startProcessingRequest(session);
+        getMailboxManager().createMailbox(StoreMailboxManager.USER_NAMESPACE_PREFIX +".INBOX",
session);
+        getMailboxManager().endProcessingRequest(session);
+        getMailboxManager().logout(session, false);
+        final AtomicBoolean fail = new AtomicBoolean(false);
+        
+        // fire of 1000 append operations
+        for (int i = 0 ; i < 1000; i++) {
+            pool.execute(new Runnable() {
+                
+                public void run() {
+                    if (fail.get()){
+                        latch.countDown();
+                        return;
+                    }
+                    
+                    MailboxSession session = getMailboxManager().createSystemSession("test",
new SimpleLog("Test"));
+
+                    try {
+                        getMailboxManager().startProcessingRequest(session);
+                        Mailbox m = getMailboxManager().getMailbox(StoreMailboxManager.USER_NAMESPACE_PREFIX
+".INBOX", session);
+                        
+                        System.out.println("Append message with uid=" + m.appendMessage(new
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), session, false,
new Flags()));
+                        getMailboxManager().endProcessingRequest(session);
+                        getMailboxManager().logout(session,false);
+                    } catch (MailboxException e) {
+                        e.printStackTrace();
+                        fail.set(true);
+                    } finally {
+                        latch.countDown();
+                    }
+                    
+                    
+                }
+            });
+        }
+        
+        latch.await();
+        
+        org.junit.Assert.assertFalse("Unable to append all messages",fail.get());
+        pool.shutdown();
+
+        
+    }
+}

Added: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java?rev=940288&view=auto
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java
(added)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java
Sun May  2 18:26:33 2010
@@ -0,0 +1,91 @@
+/****************************************************************
+ * 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.imap.functional.jcr;
+
+import java.io.File;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.james.imap.functional.AbstractStressTest;
+import org.apache.james.imap.jcr.JCRGlobalUserMailboxManager;
+import org.apache.james.imap.jcr.JCRGlobalUserSubscriptionManager;
+import org.apache.james.imap.jcr.JCRImapConstants;
+import org.apache.james.imap.jcr.JCRUtils;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.StoreMailboxManager;
+import org.junit.After;
+import org.junit.Before;
+import org.xml.sax.InputSource;
+
+public class JCRStressTest extends AbstractStressTest{
+
+    
+    private JCRGlobalUserMailboxManager mailboxManager;
+
+
+
+    private static final String JACKRABBIT_HOME = "deployment/target/jackrabbit";
+    public static final String META_DATA_DIRECTORY = "target/user-meta-data";
+    private RepositoryImpl repository;
+
+
+    
+    
+    @Before
+    public void setUp() throws RepositoryException {
+
+        new File(JACKRABBIT_HOME).delete();
+
+        String user = "user";
+        String pass = "pass";
+        String workspace = null;
+        RepositoryConfig config = RepositoryConfig.create(new InputSource(this.getClass().getClassLoader().getResourceAsStream("test-repository.xml")),
JACKRABBIT_HOME);
+        repository = RepositoryImpl.create(config);
+
+        // Register imap cnd file
+        JCRUtils.registerCnd(repository, workspace, user, pass);
+
+        // TODO: Fix the scaling stuff so the tests will pass with max scaling
+        // too
+        mailboxManager = new JCRGlobalUserMailboxManager(null, new JCRGlobalUserSubscriptionManager(repository,
workspace, user, pass, JCRImapConstants.MIN_SCALING), repository, workspace, user, pass, JCRImapConstants.MIN_SCALING);
+
+    }
+    
+    @After
+    public void tearDown() {
+        MailboxSession session = mailboxManager.createSystemSession("test", new SimpleLog("Test"));
+        try {
+            mailboxManager.deleteEverything(session);
+        } catch (MailboxException e) {
+            e.printStackTrace();
+        }
+        session.close();
+        new File(JACKRABBIT_HOME).delete();
+
+    }
+
+    @Override
+    protected StoreMailboxManager<?> getMailboxManager() {
+        return mailboxManager;
+    }
+}

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java?rev=940288&r1=940287&r2=940288&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java
(original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java
Sun May  2 18:26:33 2010
@@ -18,29 +18,25 @@
  ****************************************************************/
 package org.apache.james.imap.functional.jpa;
 
-import java.io.ByteArrayInputStream;
-import java.util.Date;
 import java.util.HashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
 
-import javax.mail.Flags;
 import javax.persistence.EntityManagerFactory;
 
 import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.imap.functional.AbstractStressTest;
 import org.apache.james.imap.jpa.JPASubscriptionManager;
 import org.apache.james.imap.jpa.openjpa.OpenJPAMailboxManager;
-import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.StoreMailboxManager;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Test;
 
-public class JPAStressTest {
+/**
+ * Proof of bug https://issues.apache.org/jira/browse/IMAP-137
+ */
+public class JPAStressTest extends AbstractStressTest{
 
     
     private OpenJPAMailboxManager mailboxManager;
@@ -82,61 +78,10 @@ public class JPAStressTest {
         }
         session.close();
     }
-    /**
-     * Proof of bug https://issues.apache.org/jira/browse/IMAP-137
-     *
-     * @throws InterruptedException
-     * @throws MailboxException
-     */
-    @Test
-    public void testStessTest() throws InterruptedException, MailboxException {
-       
-        final CountDownLatch latch = new CountDownLatch(1000);
-        final ExecutorService pool = Executors.newFixedThreadPool(500);
-        
-        MailboxSession session = mailboxManager.createSystemSession("test", new SimpleLog("Test"));
-        mailboxManager.startProcessingRequest(session);
-        mailboxManager.createMailbox(OpenJPAMailboxManager.USER_NAMESPACE_PREFIX +".INBOX",
session);
-        mailboxManager.endProcessingRequest(session);
-        mailboxManager.logout(session, false);
-        final AtomicBoolean fail = new AtomicBoolean(false);
-        
-        // fire of 1000 append operations
-        for (int i = 0 ; i < 1000; i++) {
-            pool.execute(new Runnable() {
-                
-                public void run() {
-                    if (fail.get()){
-                        latch.countDown();
-                        return;
-                    }
-                    
-                    MailboxSession session = mailboxManager.createSystemSession("test", new
SimpleLog("Test"));
-
-                    try {
-                        mailboxManager.startProcessingRequest(session);
-                        Mailbox m = mailboxManager.getMailbox(OpenJPAMailboxManager.USER_NAMESPACE_PREFIX
+".INBOX", session);
-                        
-                        System.out.println("Append message with uid=" + m.appendMessage(new
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), session, false,
new Flags()));
-                        mailboxManager.endProcessingRequest(session);
-                        mailboxManager.logout(session,false);
-                    } catch (MailboxException e) {
-                        e.printStackTrace();
-                        fail.set(true);
-                    } finally {
-                        latch.countDown();
-                    }
-                    
-                    
-                }
-            });
-        }
-        
-        latch.await();
-        
-        org.junit.Assert.assertFalse("Unable to append all messages",fail.get());
-        pool.shutdown();
 
-        
+    @Override
+    protected StoreMailboxManager<?> getMailboxManager() {
+        return mailboxManager;
     }
+   
 }



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