james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/15] james-project git commit: MAILBOX-317 Bonus: Further simplify InMemoryMailboxManager hierarchy
Date Fri, 03 Nov 2017 02:33:32 GMT
MAILBOX-317 Bonus: Further simplify InMemoryMailboxManager hierarchy


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

Branch: refs/heads/master
Commit: c301e821060e544fbd753938cc62816ce3aff36a
Parents: b9be091
Author: benwa <btellier@linagora.com>
Authored: Thu Nov 2 13:32:53 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Nov 3 09:32:33 2017 +0700

----------------------------------------------------------------------
 .../james/mailbox/MailboxManagerStressTest.java |  4 +-
 .../james/mailbox/MailboxManagerTest.java       |  2 +-
 .../inmemory/MemoryMailboxManagerProvider.java  | 43 +++-----------------
 .../MemoryMailboxManagerStressTest.java         |  3 +-
 .../inmemory/MemoryMailboxManagerTest.java      |  3 +-
 .../manager/InMemoryIntegrationResources.java   | 28 ++++++++++++-
 .../host/ElasticSearchHostSystem.java           |  8 ++--
 .../org/apache/james/JPAJamesServerMain.java    |  4 +-
 .../org/apache/james/modules/MailboxModule.java | 10 +++++
 .../modules/mailbox/MemoryMailboxModule.java    |  8 ----
 10 files changed, 56 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
index 8b4e580..1ad56e0 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
@@ -46,10 +46,10 @@ public abstract class MailboxManagerStressTest {
 
     private MailboxManager mailboxManager;
 
-    protected abstract MailboxManager provideManager();
+    protected abstract MailboxManager provideManager() throws MailboxException;
 
     
-    public void setUp() throws MailboxException, Exception {
+    public void setUp() throws Exception {
         this.mailboxManager = provideManager();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index d4e722d..be94d90 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -84,7 +84,7 @@ public abstract class MailboxManagerTest {
     private MailboxManager mailboxManager;
     private MailboxSession session;
 
-    protected abstract MailboxManager provideMailboxManager();
+    protected abstract MailboxManager provideMailboxManager() throws MailboxException;
 
     public void setUp() throws Exception {
         this.mailboxManager = new MockMailboxManager(provideMailboxManager()).getMockMailboxManager();

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
index 5d290f6..c8eedd1 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerProvider.java
@@ -20,51 +20,18 @@
 package org.apache.james.mailbox.inmemory;
 
 import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.acl.GroupMembershipResolver;
-import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.FakeAuthenticator;
-import org.apache.james.mailbox.store.FakeAuthorizator;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.StoreAttachmentManager;
-import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
-import org.apache.james.mailbox.store.StoreRightManager;
-import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
-import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-
-import com.google.common.base.Throwables;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 
 public class MemoryMailboxManagerProvider {
     private static final int LIMIT_ANNOTATIONS = 3;
     private static final int LIMIT_ANNOTATION_SIZE = 30;
 
-    public static MailboxManager provideMailboxManager() {
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
-
-        InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
-        StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory,
aclResolver, groupMembershipResolver);
-        MessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
-        DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
-        MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
-        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory,
storeRightManager,
-            LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
-        InMemoryMailboxManager mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory,
new FakeAuthenticator(), FakeAuthorizator.defaultReject(),
-            new JVMMailboxPathLocker(), messageParser, messageIdFactory, mailboxEventDispatcher,
delegatingListener,
-            annotationManager, storeRightManager);
-
-        try {
-            mailboxManager.init();
-        } catch (MailboxException e) {
-            throw Throwables.propagate(e);
-        }
-
-        return mailboxManager;
+    public static MailboxManager provideMailboxManager() throws MailboxException {
+        return new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver(),
+                LIMIT_ANNOTATIONS, LIMIT_ANNOTATION_SIZE);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerStressTest.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerStressTest.java
index b8b03c1..9212e89 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerStressTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerStressTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.inmemory;
 
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManagerStressTest;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.junit.Before;
 
 public class MemoryMailboxManagerStressTest extends MailboxManagerStressTest {
@@ -31,7 +32,7 @@ public class MemoryMailboxManagerStressTest extends MailboxManagerStressTest
{
     }
     
     @Override
-    protected MailboxManager provideManager() {
+    protected MailboxManager provideManager() throws MailboxException {
         return MemoryMailboxManagerProvider.provideMailboxManager();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerTest.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerTest.java
index c958a14..023c117 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/MemoryMailboxManagerTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.inmemory;
 
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManagerTest;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.junit.Before;
 
 public class MemoryMailboxManagerTest extends MailboxManagerTest {
@@ -31,7 +32,7 @@ public class MemoryMailboxManagerTest extends MailboxManagerTest {
     }
     
     @Override
-    protected MailboxManager provideMailboxManager() {
+    protected MailboxManager provideMailboxManager() throws MailboxException {
         return MemoryMailboxManagerProvider.provideMailboxManager();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index 3e84c32..5c6e4a6 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.inmemory.manager;
 
+import java.util.function.BiFunction;
+
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
@@ -38,6 +40,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.FakeAuthenticator;
 import org.apache.james.mailbox.store.FakeAuthorizator;
+import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
 import org.apache.james.mailbox.store.StoreMailboxManager;
@@ -58,12 +61,33 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
 
     @Override
     public StoreMailboxManager createMailboxManager(GroupMembershipResolver groupMembershipResolver)
throws MailboxException {
+        return createMailboxManager(groupMembershipResolver,
+            ((storeRightManager, inMemoryMailboxSessionMapperFactory) ->
+                new StoreMailboxAnnotationManager(
+                    inMemoryMailboxSessionMapperFactory,
+                    storeRightManager)));
+    }
+
+    public StoreMailboxManager createMailboxManager(GroupMembershipResolver groupMembershipResolver,
+                                                    int limitAnnotationCount, int limitAnnotationSize)
throws MailboxException {
+        return createMailboxManager(groupMembershipResolver,
+            ((storeRightManager, inMemoryMailboxSessionMapperFactory) ->
+             new StoreMailboxAnnotationManager(
+                 inMemoryMailboxSessionMapperFactory,
+                 storeRightManager,
+                 limitAnnotationCount,
+                 limitAnnotationSize)));
+    }
+
+    private StoreMailboxManager createMailboxManager(GroupMembershipResolver groupMembershipResolver,
+                                                    BiFunction<StoreRightManager, InMemoryMailboxSessionMapperFactory,
StoreMailboxAnnotationManager> annotationManagerBiFunction) throws MailboxException {
         FakeAuthenticator fakeAuthenticator = new FakeAuthenticator();
         fakeAuthenticator.addUser(ManagerTestResources.USER, ManagerTestResources.USER_PASS);
         fakeAuthenticator.addUser(ManagerTestResources.OTHER_USER, ManagerTestResources.OTHER_USER_PASS);
         InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
         StoreRightManager storeRightManager = new StoreRightManager(mailboxSessionMapperFactory,
new UnionMailboxACLResolver(), groupMembershipResolver);
-        StoreMailboxAnnotationManager annotationManager = new StoreMailboxAnnotationManager(mailboxSessionMapperFactory,
storeRightManager);
+        StoreMailboxAnnotationManager annotationManager = annotationManagerBiFunction
+            .apply(storeRightManager, mailboxSessionMapperFactory);
 
         DefaultDelegatingMailboxListener delegatingListener = new DefaultDelegatingMailboxListener();
         MailboxEventDispatcher mailboxEventDispatcher = new MailboxEventDispatcher(delegatingListener);
@@ -71,7 +95,7 @@ public class InMemoryIntegrationResources implements IntegrationResources<StoreM
             mailboxSessionMapperFactory,
             fakeAuthenticator,
             FakeAuthorizator.defaultReject(),
-            new NoMailboxPathLocker(),
+            new JVMMailboxPathLocker(),
             new MessageParser(),
             new InMemoryMessageId.Factory(),
             mailboxEventDispatcher,

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 9b36b88..a7f2c76 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -112,10 +112,12 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
                 MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, MailboxElasticSearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(),
IndexAttachments.YES));
 
-        InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources();
-        this.mailboxManager = inMemoryIntegrationResources.createMailboxManager(new SimpleGroupMembershipResolver());
+        this.mailboxManager = new InMemoryIntegrationResources()
+            .createMailboxManager(new SimpleGroupMembershipResolver(),
+                authenticator,
+                authorizator);
         this.mailboxManager.setMessageSearchIndex(searchIndex);
-        this.mailboxManager.removeGlobalListener(searchIndex, new MockMailboxSession("admin"));
+        this.mailboxManager.addGlobalListener(searchIndex, new MockMailboxSession("admin"));
 
         final ImapProcessor defaultImapProcessorFactory =
             DefaultImapProcessorFactory.createDefaultProcessor(this.mailboxManager,

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
index e4a63b2..783b1bd 100644
--- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -22,6 +22,7 @@ package org.apache.james;
 import org.apache.james.modules.MailboxModule;
 import org.apache.james.modules.data.JPADataModule;
 import org.apache.james.modules.data.SieveFileRepositoryModule;
+import org.apache.james.modules.mailbox.DefaultEventModule;
 import org.apache.james.modules.mailbox.JPAMailboxModule;
 import org.apache.james.modules.mailbox.LuceneSearchMailboxModule;
 import org.apache.james.modules.protocols.IMAPServerModule;
@@ -70,7 +71,8 @@ public class JPAJamesServerMain {
         new MailboxModule(),
         new NoJwtModule(),
         new RawPostDequeueDecoratorModule(),
-        new SieveFileRepositoryModule());
+        new SieveFileRepositoryModule(),
+        new DefaultEventModule());
 
     public static void main(String[] args) throws Exception {
         GuiceJamesServer server = new GuiceJamesServer()

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
index a91ada3..dc8bdc7 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
@@ -18,9 +18,14 @@
  ****************************************************************/
 package org.apache.james.modules;
 
+import org.apache.james.mailbox.acl.GroupMembershipResolver;
+import org.apache.james.mailbox.acl.MailboxACLResolver;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.utils.GuiceProbe;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
 import com.google.inject.multibindings.Multibinder;
 
 public class MailboxModule extends AbstractModule {
@@ -31,6 +36,11 @@ public class MailboxModule extends AbstractModule {
         probeMultiBinder.addBinding().to(MailboxProbeImpl.class);
         probeMultiBinder.addBinding().to(QuotaProbesImpl.class);
         probeMultiBinder.addBinding().to(ACLProbeImpl.class);
+
+        bind(UnionMailboxACLResolver.class).in(Scopes.SINGLETON);
+        bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class);
+        bind(SimpleGroupMembershipResolver.class).in(Scopes.SINGLETON);
+        bind(GroupMembershipResolver.class).to(SimpleGroupMembershipResolver.class);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c301e821/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
index 301190c..204dbf3 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
@@ -29,10 +29,6 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.SubscriptionManager;
-import org.apache.james.mailbox.acl.GroupMembershipResolver;
-import org.apache.james.mailbox.acl.MailboxACLResolver;
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.inmemory.InMemoryId;
@@ -99,8 +95,6 @@ public class MemoryMailboxModule extends AbstractModule {
         bind(Authorizator.class).to(UserRepositoryAuthorizator.class);
         bind(MailboxManager.class).to(InMemoryMailboxManager.class);
         bind(MessageIdManager.class).to(StoreMessageIdManager.class);
-        bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class);
-        bind(GroupMembershipResolver.class).to(SimpleGroupMembershipResolver.class);
         bind(AttachmentManager.class).to(StoreAttachmentManager.class);
 
         bind(MessageSearchIndex.class).to(SimpleMessageSearchIndex.class);
@@ -115,8 +109,6 @@ public class MemoryMailboxModule extends AbstractModule {
         bind(UserRepositoryAuthenticator.class).in(Scopes.SINGLETON);
         bind(UserRepositoryAuthorizator.class).in(Scopes.SINGLETON);
         bind(InMemoryMailboxManager.class).in(Scopes.SINGLETON);
-        bind(UnionMailboxACLResolver.class).in(Scopes.SINGLETON);
-        bind(SimpleGroupMembershipResolver.class).in(Scopes.SINGLETON);
         bind(InMemoryMessageId.Factory.class).in(Scopes.SINGLETON);
         bind(StoreMessageIdManager.class).in(Scopes.SINGLETON);
         bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON);


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