Repository: james-project Updated Branches: refs/heads/master 0dd617259 -> 7c89479a4
JAMES-1812 Use user from MailboxPath when reindexing Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7c89479a Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7c89479a Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7c89479a Branch: refs/heads/master Commit: 7c89479a4a77a2d1217d6d15b8be77754067b43f Parents: 0dd6172 Author: Antoine Duprat <adup...@linagora.com> Authored: Wed Jul 27 09:17:17 2016 +0200 Committer: Antoine Duprat <adup...@linagora.com> Committed: Wed Jul 27 09:17:17 2016 +0200 ---------------------------------------------------------------------- .../james/mailbox/indexer/ReIndexerImpl.java | 2 +- .../mailbox/indexer/ReIndexerImplTest.java | 41 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/7c89479a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java ---------------------------------------------------------------------- diff --git a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java index f6da016..bc7200d 100644 --- a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java +++ b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java @@ -77,7 +77,7 @@ public class ReIndexerImpl implements ReIndexer { } public void reIndex(MailboxPath path) throws MailboxException { - MailboxSession mailboxSession = mailboxManager.createSystemSession("re-indexing", LOGGER); + MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser(), LOGGER); reIndex(path, mailboxSession); } http://git-wip-us.apache.org/repos/asf/james-project/blob/7c89479a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java ---------------------------------------------------------------------- diff --git a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java index 45ba909..dfa3b48 100644 --- a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java +++ b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java @@ -32,6 +32,7 @@ import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.mock.MockMailboxSession; +import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; @@ -49,6 +50,8 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.slf4j.Logger; +import com.google.common.collect.ImmutableList; + public class ReIndexerImplTest { public static final MailboxPath INBOX = new MailboxPath("#private", "be...@apache.org", "INBOX"); @@ -117,4 +120,42 @@ public class ReIndexerImplTest { verify(messageSearchIndex).deleteAll(any(MailboxSession.class), eq(mailbox)); verifyNoMoreInteractions(mailboxMapper, mailboxSessionMapperFactory, messageSearchIndex, messageMapper, mailboxMapper); } + + @Test + public void mailboxPathUserShouldBeUsedWhenReIndexing() throws Exception { + MockMailboxSession systemMailboxSession = new MockMailboxSession("re-indexing"); + when(mailboxManager.createSystemSession(eq("re-indexing"), any(Logger.class))) + .thenReturn(systemMailboxSession); + MailboxMapper mailboxMapper = mock(MailboxMapper.class); + when(mailboxSessionMapperFactory.getMailboxMapper(systemMailboxSession)) + .thenReturn(mailboxMapper); + + String user1 = "us...@james.org"; + MailboxPath user1MailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, user1, "Inbox"); + MockMailboxSession user1MailboxSession = new MockMailboxSession(user1); + when(mailboxManager.createSystemSession(eq(user1), any(Logger.class))) + .thenReturn(user1MailboxSession); + MailboxMapper user1MailboxMapper = mock(MailboxMapper.class); + when(mailboxSessionMapperFactory.getMailboxMapper(user1MailboxSession)) + .thenReturn(user1MailboxMapper); + Mailbox user1Mailbox = mock(Mailbox.class); + when(user1MailboxMapper.findMailboxByPath(user1MailboxPath)) + .thenReturn(user1Mailbox); + MessageMapper user1MessageMapper = mock(MessageMapper.class); + when(mailboxSessionMapperFactory.getMessageMapper(user1MailboxSession)) + .thenReturn(user1MessageMapper); + MailboxMessage user1MailboxMessage = mock(MailboxMessage.class); + when(user1MessageMapper.findInMailbox(user1Mailbox, MessageRange.all(), MessageMapper.FetchType.Full, ReIndexerImpl.NO_LIMIT)) + .thenReturn(ImmutableList.of(user1MailboxMessage).iterator()); + when(user1MailboxMessage.getUid()) + .thenReturn(1l); + + when(mailboxManager.list(systemMailboxSession)) + .thenReturn(ImmutableList.of(user1MailboxPath)); + + reIndexer.reIndex(); + + verify(messageSearchIndex).deleteAll(user1MailboxSession, user1Mailbox); + verify(messageSearchIndex).add(user1MailboxSession, user1Mailbox, user1MailboxMessage); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org