james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/10] james-project git commit: MAILBOX-351 ReIndexer should allow to reIndex per MailboxId
Date Thu, 29 Nov 2018 03:53:19 GMT
MAILBOX-351 ReIndexer should allow to reIndex per MailboxId


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

Branch: refs/heads/master
Commit: 1bd2c290518ef0305d0082c7208314ee30cebef6
Parents: 655d35b
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Nov 23 15:34:11 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 29 10:52:45 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/indexer/ReIndexer.java |  3 ++
 .../mailbox/tools/indexer/ReIndexerImpl.java    | 25 ++++++++--
 .../tools/indexer/ReIndexerPerformer.java       |  4 +-
 .../indexer/SingleMailboxReindexingTask.java    | 24 +++++----
 .../mailbox/tools/indexer/ThrowsReIndexer.java  |  6 +++
 .../indexer/CassandraReIndexerImplTest.java     |  4 +-
 .../tools/indexer/ReIndexerImplTest.java        | 51 +++++++++++++++++++-
 .../webadmin/routes/ReindexingRoutesTest.java   |  4 +-
 8 files changed, 102 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
index 817307b..5d4dd3a 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.indexer;
 import org.apache.james.core.User;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.task.Task;
 
@@ -31,6 +32,8 @@ public interface ReIndexer {
 
     Task reIndex(MailboxPath path) throws MailboxException;
 
+    Task reIndex(MailboxId mailboxId) throws MailboxException;
+
     Task reIndex() throws MailboxException;
 
     Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException;

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
index c32c533..d1c7b9e 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -22,9 +22,15 @@ package org.apache.mailbox.tools.indexer;
 import javax.inject.Inject;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.task.Task;
 
 /**
@@ -39,15 +45,28 @@ import org.apache.james.task.Task;
 public class ReIndexerImpl implements ReIndexer {
 
     private final ReIndexerPerformer reIndexerPerformer;
+    private final MailboxManager mailboxManager;
+    private final MailboxSessionMapperFactory mapperFactory;
 
     @Inject
-    public ReIndexerImpl(ReIndexerPerformer reIndexerPerformer) {
+    public ReIndexerImpl(ReIndexerPerformer reIndexerPerformer, MailboxManager mailboxManager,
MailboxSessionMapperFactory mapperFactory) {
         this.reIndexerPerformer = reIndexerPerformer;
+        this.mailboxManager = mailboxManager;
+        this.mapperFactory = mapperFactory;
     }
 
     @Override
-    public Task reIndex(MailboxPath path) {
-        return new SingleMailboxReindexingTask(reIndexerPerformer, path);
+    public Task reIndex(MailboxPath path) throws MailboxException {
+        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
+        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
+        return new SingleMailboxReindexingTask(reIndexerPerformer, mailbox);
+    }
+
+    @Override
+    public Task reIndex(MailboxId mailboxId) throws MailboxException {
+        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
+        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
+        return new SingleMailboxReindexingTask(reIndexerPerformer, mailbox);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index b86316f..552ddca 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -66,9 +66,7 @@ public class ReIndexerPerformer {
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
     }
 
-    Task.Result reIndex(MailboxPath path, ReprocessingContext reprocessingContext) throws
MailboxException {
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser());
-        Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
+    Task.Result reIndex(Mailbox mailbox, ReprocessingContext reprocessingContext) throws
MailboxException {
         return reIndexSingleMailbox(mailbox.getMailboxId(), reprocessingContext);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
index fc9f834..c3f024b 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
@@ -24,7 +24,7 @@ import java.util.Optional;
 import javax.inject.Inject;
 
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskExecutionDetails;
 
@@ -33,16 +33,20 @@ public class SingleMailboxReindexingTask implements Task {
     public static final String MAILBOX_RE_INDEXING = "mailboxReIndexing";
 
     public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation
{
-        private final MailboxPath mailboxPath;
+        private final Mailbox mailbox;
         private final ReprocessingContext reprocessingContext;
 
-        AdditionalInformation(MailboxPath mailboxPath, ReprocessingContext reprocessingContext)
{
-            this.mailboxPath = mailboxPath;
+        AdditionalInformation(Mailbox mailbox, ReprocessingContext reprocessingContext) {
+            this.mailbox = mailbox;
             this.reprocessingContext = reprocessingContext;
         }
 
         public String getMailboxPath() {
-            return mailboxPath.asString();
+            return mailbox.generateAssociatedPath().asString();
+        }
+
+        public String getMailboxId() {
+            return mailbox.getMailboxId().serialize();
         }
 
         public int getSuccessfullyReprocessMailCount() {
@@ -55,22 +59,22 @@ public class SingleMailboxReindexingTask implements Task {
     }
 
     private final ReIndexerPerformer reIndexerPerformer;
-    private final MailboxPath path;
+    private final Mailbox mailbox;
     private final AdditionalInformation additionalInformation;
     private final ReprocessingContext reprocessingContext;
 
     @Inject
-    public SingleMailboxReindexingTask(ReIndexerPerformer reIndexerPerformer, MailboxPath
path) {
+    public SingleMailboxReindexingTask(ReIndexerPerformer reIndexerPerformer, Mailbox mailbox)
{
         this.reIndexerPerformer = reIndexerPerformer;
-        this.path = path;
+        this.mailbox = mailbox;
         this.reprocessingContext = new ReprocessingContext();
-        this.additionalInformation = new AdditionalInformation(path, reprocessingContext);
+        this.additionalInformation = new AdditionalInformation(mailbox, reprocessingContext);
     }
 
     @Override
     public Result run() {
         try {
-            return reIndexerPerformer.reIndex(path, reprocessingContext);
+            return reIndexerPerformer.reIndex(mailbox, reprocessingContext);
         } catch (MailboxException e) {
             return Result.PARTIAL;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
index 5ffb02b..f5016a1 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
@@ -23,6 +23,7 @@ import org.apache.james.core.User;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.task.Task;
 
@@ -34,6 +35,11 @@ public class ThrowsReIndexer implements ReIndexer {
     }
 
     @Override
+    public Task reIndex(MailboxId mailboxId) throws MailboxException {
+        throw new MailboxException("Not implemented");
+    }
+
+    @Override
     public Task reIndex() throws MailboxException {
         throw new MailboxException("Not implemented");
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
index 6c55478..8a95a85 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
@@ -64,7 +64,9 @@ public class CassandraReIndexerImplTest {
         mailboxManager = CassandraMailboxManagerProvider.provideMailboxManager(cassandra.getConf(),
cassandra.getTypesProvider());
         MailboxSessionMapperFactory mailboxSessionMapperFactory = mailboxManager.getMapperFactory();
         messageSearchIndex = mock(ListeningMessageSearchIndex.class);
-        reIndexer = new ReIndexerImpl(new ReIndexerPerformer(mailboxManager, messageSearchIndex,
mailboxSessionMapperFactory));
+        reIndexer = new ReIndexerImpl(new ReIndexerPerformer(mailboxManager, messageSearchIndex,
mailboxSessionMapperFactory),
+            mailboxManager,
+            mailboxSessionMapperFactory);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
index 74e834a..70a74ca 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
@@ -20,6 +20,7 @@
 package org.apache.mailbox.tools.indexer;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -30,7 +31,9 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.model.ComposedMessageId;
@@ -58,7 +61,9 @@ public class ReIndexerImplTest {
         mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver());
         MailboxSessionMapperFactory mailboxSessionMapperFactory = mailboxManager.getMapperFactory();
         messageSearchIndex = mock(ListeningMessageSearchIndex.class);
-        reIndexer = new ReIndexerImpl(new ReIndexerPerformer(mailboxManager, messageSearchIndex,
mailboxSessionMapperFactory));
+        reIndexer = new ReIndexerImpl(new ReIndexerPerformer(mailboxManager, messageSearchIndex,
mailboxSessionMapperFactory),
+            mailboxManager,
+            mailboxSessionMapperFactory);
     }
 
     @Test
@@ -154,4 +159,48 @@ public class ReIndexerImplTest {
         assertThat(messageCaptor.getValue()).matches(message -> message.getMailboxId().equals(mailboxId)
             && message.getUid().equals(createdMessage.getUid()));
     }
+
+    @Test
+    void mailboxIdReIndexShouldBeWellPerformed() throws Exception {
+        MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+        MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
+        ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession)
+            .appendMessage(
+                MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"),
+                systemSession);
+
+        reIndexer.reIndex(mailboxId).run();
+        ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class);
+        ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class);
+
+        verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxCaptor.capture());
+        verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor.capture(),
messageCaptor.capture());
+        verifyNoMoreInteractions(messageSearchIndex);
+
+        assertThat(mailboxCaptor.getValue()).matches(mailbox -> mailbox.getMailboxId().equals(mailboxId));
+        assertThat(messageCaptor.getValue()).matches(message -> message.getMailboxId().equals(mailboxId)
+            && message.getUid().equals(createdMessage.getUid()));
+    }
+
+    @Test
+    void mailboxIdReIndexShouldBeWellPerformedWhenEmptyMailbox() throws Exception {
+        MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+        MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
+
+        reIndexer.reIndex(mailboxId).run();
+        ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class);
+
+        verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxCaptor.capture());
+        verifyNoMoreInteractions(messageSearchIndex);
+
+        assertThat(mailboxCaptor.getValue()).matches(mailbox -> mailbox.getMailboxId().equals(mailboxId));
+    }
+
+    @Test
+    void mailboxIdReIndexShouldFailWhenMailboxNotFound() {
+        MailboxId mailboxId = InMemoryId.of(42);
+
+        assertThatThrownBy(() -> reIndexer.reIndex(mailboxId))
+            .isInstanceOf(MailboxNotFoundException.class);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bd2c290/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
index c0e90cf..f0c6459 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
@@ -85,7 +85,9 @@ class ReindexingRoutesTest {
             new ReIndexerPerformer(
                 mailboxManager,
                 searchIndex,
-                mailboxManager.getMapperFactory()));
+                mailboxManager.getMapperFactory()),
+            mailboxManager,
+            mailboxManager.getMapperFactory());
         JsonTransformer jsonTransformer = new JsonTransformer();
 
         webAdminServer = WebAdminUtils.createWebAdminServer(


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