james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r420520 - in /james/server/trunk/src: java/org/apache/james/mailrepository/ java/org/apache/james/mailrepository/filepair/ test/org/apache/james/mailrepository/ test/org/apache/james/test/mock/avalon/
Date Mon, 10 Jul 2006 13:34:28 GMT
Author: bago
Date: Mon Jul 10 06:34:26 2006
New Revision: 420520

URL: http://svn.apache.org/viewvc?rev=420520&view=rev
Log:
Remove AbstractFileRepository optimisation that caused body message corruption when using
file repositories (JAMES-559)

Added:
    james/server/trunk/src/test/org/apache/james/mailrepository/
    james/server/trunk/src/test/org/apache/james/mailrepository/AvalonMailRepositoryTest.java
  (with props)
Modified:
    james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
    james/server/trunk/src/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java

Modified: james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java?rev=420520&r1=420519&r2=420520&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
(original)
+++ james/server/trunk/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
Mon Jul 10 06:34:26 2006
@@ -75,7 +75,7 @@
     private boolean fifo;
     private boolean cacheKeys; // experimental: for use with write mostly repositories such
as spam and error
 
-    private void setStore(Store store) {
+    void setStore(Store store) {
         this.store = store;
     }
 

Modified: james/server/trunk/src/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java?rev=420520&r1=420519&r2=420520&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
(original)
+++ james/server/trunk/src/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
Mon Jul 10 06:34:26 2006
@@ -17,29 +17,29 @@
 
 package org.apache.james.mailrepository.filepair;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
 import org.apache.avalon.cornerstone.services.store.Repository;
-import org.apache.james.util.io.ExtensionFileFilter;
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.util.io.ExtensionFileFilter;
 
-import javax.mail.util.SharedFileInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  * This an abstract class implementing functionality for creating a file-store.
@@ -258,7 +258,12 @@
     protected InputStream getInputStream( final String key )
         throws IOException
     {
-        return new SharedFileInputStream( encode( key ) );
+        // This was changed to SharedFileInputStream but reverted to 
+        // fix JAMES-559. Usign SharedFileInputStream should be a good
+        // performance improvement, but more checks have to be done
+        // on the repository side to avoid concurrency in reading and
+        // writing the same file.
+        return new FileInputStream( encode( key ) );
     }
 
     protected OutputStream getOutputStream( final String key )
@@ -266,7 +271,7 @@
     {
         return new FileOutputStream( getFile( key ) );
     }
-
+    
     /**
      * Remove the object associated to the given key.
      */

Added: james/server/trunk/src/test/org/apache/james/mailrepository/AvalonMailRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/mailrepository/AvalonMailRepositoryTest.java?rev=420520&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/mailrepository/AvalonMailRepositoryTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/mailrepository/AvalonMailRepositoryTest.java
Mon Jul 10 06:34:26 2006
@@ -0,0 +1,112 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.core.MailImpl;
+import org.apache.james.core.MimeMessageCopyOnWriteProxy;
+import org.apache.james.core.MimeMessageInputStreamSource;
+import org.apache.james.mailrepository.filepair.File_Persistent_Object_Repository;
+import org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository;
+import org.apache.james.test.mock.avalon.MockContext;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockStore;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class AvalonMailRepositoryTest extends TestCase {
+
+    String content = "Subject: test\r\nAAAContent-Transfer-Encoding: text/plain";
+    String sep = "\r\n\r\n";
+    String body = "original body\r\n.\r\n";
+
+    /**
+     * This test has been written as a proof to:
+     * http://issues.apache.org/jira/browse/JAMES-559
+     */
+    public void testJames559() throws Exception {
+        AvalonMailRepository mr = new AvalonMailRepository();
+        MockStore mockStore = new MockStore();
+        File_Persistent_Stream_Repository file_Persistent_Stream_Repository = new File_Persistent_Stream_Repository();
+        MockContext mockContext = new MockContext(new File("."));
+        file_Persistent_Stream_Repository.contextualize(mockContext);
+        file_Persistent_Stream_Repository.enableLogging(new MockLogger());
+        DefaultConfiguration defaultConfiguration2 = new DefaultConfiguration("conf");
+        defaultConfiguration2.setAttribute("destinationURL", "file://var/mr");
+        file_Persistent_Stream_Repository.configure(defaultConfiguration2);
+        file_Persistent_Stream_Repository.initialize();
+        mockStore.add("STREAM.mr", file_Persistent_Stream_Repository);
+        File_Persistent_Object_Repository file_Persistent_Object_Repository = new File_Persistent_Object_Repository();
+        file_Persistent_Object_Repository.contextualize(mockContext);
+        file_Persistent_Object_Repository.enableLogging(new MockLogger());
+        DefaultConfiguration defaultConfiguration22 = new DefaultConfiguration("conf");
+        defaultConfiguration22.setAttribute("destinationURL", "file://var/mr");
+        file_Persistent_Object_Repository.configure(defaultConfiguration22);
+        file_Persistent_Object_Repository.initialize();
+        mockStore.add("OBJECT.mr", file_Persistent_Object_Repository);
+        mr.setStore(mockStore);
+
+        mr.enableLogging(new MockLogger());
+        DefaultConfiguration defaultConfiguration = new DefaultConfiguration("ReposConf");
+        defaultConfiguration.setAttribute("destinationURL","file://var/mr");
+        defaultConfiguration.setAttribute("type","MAIL");
+        mr.configure(defaultConfiguration);
+        mr.initialize();
+
+        MimeMessageInputStreamSource mmis = null;
+        try {
+            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream((content+sep+body).getBytes()));
+        } catch (MessagingException e) {
+        }
+        MimeMessage mimeMessage = new MimeMessageCopyOnWriteProxy(mmis);
+        Collection recipients = new ArrayList();
+        recipients.add(new MailAddress("rec1","domain.com"));
+        recipients.add(new MailAddress("rec2","domain.com"));
+        MailImpl m = new MailImpl("mail1",new MailAddress("sender","domain.com"),recipients,mimeMessage);
+        mr.store(m);
+        
+        Mail m2 = mr.retrieve("mail1");
+        m2.getMessage().setHeader("X-Header", "foobar");
+        m2.getMessage().saveChanges();
+        
+        mr.store(m2);
+        // ALWAYS remember to dispose mails!
+        ContainerUtil.dispose(m2);
+        
+        m2 = mr.retrieve("mail1");
+        assertEquals(m.getMessage().getContent().toString(),m2.getMessage().getContent().toString());
+        
+        m.dispose();
+        ContainerUtil.dispose(m2);
+        
+        mr.remove("mail1");
+
+    }
+}
+

Propchange: james/server/trunk/src/test/org/apache/james/mailrepository/AvalonMailRepositoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java?rev=420520&r1=420519&r2=420520&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java (original)
+++ james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java Mon Jul 10
06:34:26 2006
@@ -47,10 +47,15 @@
         if (object instanceof Configuration) {
             Configuration repConf = (Configuration) object;
             try {
+                String type = repConf.getAttribute("type");
+                String prefix = "";
+                if (!"MAIL".equals(type) && !"SPOOL".equals(type)) {
+                    prefix = type+".";
+                }
                 String attribute = repConf.getAttribute("destinationURL");
                 String[] strings = attribute.split("/");
                 if (strings.length > 0) {
-                    object = strings[strings.length-1];
+                    return prefix+strings[strings.length-1];
                 }
             } catch (ConfigurationException e) {
                 throw new RuntimeException("test configuration setup failed");



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