JAMES-1983 CLI test for re-indexing
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f1e4b343 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f1e4b343 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f1e4b343 Branch: refs/heads/master Commit: f1e4b343d1ba334cbe7e9c93e78650ab7f4d8ed8 Parents: b052f86 Author: benwa <btell...@linagora.com> Authored: Sat Apr 1 18:02:48 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Mon Apr 3 18:09:33 2017 +0700 ---------------------------------------------------------------------- .../james/cli/DataCommandsIntegrationTest.java | 13 +--- .../cli/MailboxCommandsIntegrationTest.java | 13 +--- .../james/cli/QuotaCommandsIntegrationTest.java | 5 +- .../cli/ReindexCommandIntegrationTest.java | 77 ++++++++++++++++++++ .../cli/SieveQuotaCommandsIntegrationTest.java | 13 +--- .../modules/mailbox/MemoryMailboxModule.java | 15 ++++ 6 files changed, 96 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java index d1e4ee9..1e3a6d3 100644 --- a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java +++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java @@ -51,14 +51,6 @@ public class DataCommandsIntegrationTest { public static final String MAIL_ADDRESS = USER + "@" + DOMAIN_COM; public static final String PASSWORD = "12345"; - @Singleton - private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition { - @Inject - private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) { - super("memory-mailboxmanager", manager); - } - } - @Rule public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule(); private GuiceJamesServer guiceJamesServer; @@ -67,10 +59,7 @@ public class DataCommandsIntegrationTest { @Before public void setUp() throws Exception { guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(), - binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)), - binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class) - .addBinding() - .to(MemoryMailboxManagerDefinition.class)); + binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class))); guiceJamesServer.start(); dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java index 4aabb44..074a22a 100644 --- a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java +++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java @@ -46,14 +46,6 @@ public class MailboxCommandsIntegrationTest { public static final String USER = "user"; public static final String MAILBOX = "mailbox"; - @Singleton - private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition { - @Inject - private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) { - super("memory-mailboxmanager", manager); - } - } - @Rule public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule(); private GuiceJamesServer guiceJamesServer; @@ -62,10 +54,7 @@ public class MailboxCommandsIntegrationTest { @Before public void setUp() throws Exception { guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(), - binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)), - binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class) - .addBinding() - .to(MemoryMailboxManagerDefinition.class)); + binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class))); guiceJamesServer.start(); mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java index b20dd87..517457d 100644 --- a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java +++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java @@ -61,10 +61,7 @@ public class QuotaCommandsIntegrationTest { @Before public void setUp() throws Exception { guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(), - binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)), - binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class) - .addBinding() - .to(MemoryMailboxManagerDefinition.class)); + binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class))); guiceJamesServer.start(); quotaProbe = guiceJamesServer.getProbe(QuotaProbesImpl.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java new file mode 100644 index 0000000..ac7bfd7 --- /dev/null +++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java @@ -0,0 +1,77 @@ +/**************************************************************** + * 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.cli; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.apache.james.GuiceJamesServer; +import org.apache.james.MemoryJmapTestRule; +import org.apache.james.mailbox.indexer.ReIndexer; +import org.apache.james.mailbox.model.MailboxConstants; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex; +import org.apache.james.modules.server.JMXServerModule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import com.google.inject.name.Names; + +public class ReindexCommandIntegrationTest { + public static final String USER = "user"; + private ReIndexer reIndexer; + + @Rule + public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule(); + private GuiceJamesServer guiceJamesServer; + + @Before + public void setUp() throws Exception { + reIndexer = mock(ReIndexer.class); + guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(), + binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class))) + .overrideWith(binder -> binder.bind(ReIndexer.class) + .annotatedWith(Names.named("reindexer")).toInstance(reIndexer)); + guiceJamesServer.start(); + } + + @After + public void tearDown() { + guiceJamesServer.stop(); + } + + @Test + public void reindexAllShouldWork() throws Exception { + ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "reindexall"}); + + verify(reIndexer).reIndex(); + } + + @Test + public void reindexMailboxShouldWork() throws Exception { + String mailbox = "mailbox"; + ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "reindexmailbox", MailboxConstants.USER_NAMESPACE, USER, mailbox}); + + verify(reIndexer).reIndex(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, mailbox)); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java index 3cf3a1b..bc2fb30 100644 --- a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java +++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java @@ -46,14 +46,6 @@ import com.google.inject.multibindings.Multibinder; public class SieveQuotaCommandsIntegrationTest { public static final String USER = "user"; - @Singleton - private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition { - @Inject - private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) { - super("memory-mailboxmanager", manager); - } - } - @Rule public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule(); @Rule @@ -66,10 +58,7 @@ public class SieveQuotaCommandsIntegrationTest { @Before public void setUp() throws Exception { guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(), - binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)), - binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class) - .addBinding() - .to(MemoryMailboxManagerDefinition.class)) + binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class))) .overrideWith(new TestFilesystemModule(temporaryFolder)); guiceJamesServer.start(); sieveProbe = guiceJamesServer.getProbe(SieveProbeImpl.class); http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/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 7b1de77..0b28b08 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 @@ -63,10 +63,13 @@ import org.apache.james.mailbox.store.search.MessageSearchIndex; import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex; import org.apache.james.mailbox.store.user.SubscriptionMapperFactory; import org.apache.james.modules.Names; +import org.apache.james.utils.MailboxManagerDefinition; import com.google.inject.AbstractModule; +import com.google.inject.Inject; import com.google.inject.Provides; import com.google.inject.Scopes; +import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Named; public class MemoryMailboxModule extends AbstractModule { @@ -114,6 +117,10 @@ public class MemoryMailboxModule extends AbstractModule { bind(InMemoryMessageIdManager.class).in(Scopes.SINGLETON); bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON); bind(StoreAttachmentManager.class).in(Scopes.SINGLETON); + + Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class) + .addBinding() + .to(MemoryMailboxManagerDefinition.class); } @Provides @Named(Names.MAILBOXMANAGER_NAME) @Singleton @@ -125,4 +132,12 @@ public class MemoryMailboxModule extends AbstractModule { mailboxManager.init(); return mailboxManager; } + + @Singleton + private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition { + @Inject + private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) { + super("memory-mailboxmanager", manager); + } + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org