JAMESâ2246 Avoiding delayed checks for validating an action did not happened
To avoid a negative assertion, we create an alternative action. In the case of mailet pipelines, to better fit in an integration test scenario, this action can be storing an undelivered email in a repository. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8eb8bf1a Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8eb8bf1a Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8eb8bf1a Branch: refs/heads/master Commit: 8eb8bf1a4303da9ba23714b0e0aea5a60b513eb1 Parents: 51b8f72 Author: benwa <btell...@linagora.com> Authored: Wed Dec 6 09:33:49 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Fri Dec 8 17:34:45 2017 +0700 ---------------------------------------------------------------------- .../server/MailStoreRepositoryModule.java | 3 ++ .../james/utils/MailRepositoryProbeImpl.java | 45 ++++++++++++++++++++ .../mailets/NetworkMatcherIntegrationTest.java | 35 +++++++-------- .../james/mailets/SmtpAuthIntegrationTest.java | 13 +++--- 4 files changed, 73 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/8eb8bf1a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java index 4ed9cd7..6a8e3b2 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java @@ -28,7 +28,9 @@ import org.apache.james.mailrepository.api.MailRepositoryStore; import org.apache.james.mailrepository.file.FileMailRepository; import org.apache.james.utils.ConfigurationPerformer; import org.apache.james.utils.ConfigurationProvider; +import org.apache.james.utils.GuiceProbe; import org.apache.james.utils.InMemoryMailRepositoryStore; +import org.apache.james.utils.MailRepositoryProbeImpl; import org.apache.james.utils.MailRepositoryProvider; import com.google.common.base.Throwables; @@ -49,6 +51,7 @@ public class MailStoreRepositoryModule extends AbstractModule { Multibinder<MailRepositoryProvider> multibinder = Multibinder.newSetBinder(binder(), MailRepositoryProvider.class); multibinder.addBinding().to(FileMailRepositoryProvider.class); Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(MailRepositoryStoreModuleConfigurationPerformer.class); + Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().to(MailRepositoryProbeImpl.class); } public static class FileMailRepositoryProvider implements MailRepositoryProvider { http://git-wip-us.apache.org/repos/asf/james-project/blob/8eb8bf1a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/MailRepositoryProbeImpl.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/MailRepositoryProbeImpl.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/MailRepositoryProbeImpl.java new file mode 100644 index 0000000..baac629 --- /dev/null +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/MailRepositoryProbeImpl.java @@ -0,0 +1,45 @@ +/**************************************************************** + * 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.utils; + +import javax.inject.Inject; + +import org.apache.james.mailrepository.api.MailRepositoryStore; + +import com.google.common.collect.Iterators; + +public class MailRepositoryProbeImpl implements GuiceProbe { + + private final MailRepositoryStore repositoryStore; + + @Inject + public MailRepositoryProbeImpl(MailRepositoryStore repositoryStore) { + this.repositoryStore = repositoryStore; + } + + /** + * Get the count of email currently stored in a given repository + */ + public int getRepositoryMailCount(String url) throws Exception { + return Iterators.size(repositoryStore.select(url) + .list()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/8eb8bf1a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java index b317ae8..e70d4e4 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/NetworkMatcherIntegrationTest.java @@ -21,8 +21,6 @@ package org.apache.james.mailets; import static org.assertj.core.api.Assertions.assertThat; -import java.util.concurrent.TimeUnit; - import org.apache.james.MemoryJamesServerMain; import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetConfiguration; @@ -30,14 +28,15 @@ import org.apache.james.mailets.configuration.MailetContainer; import org.apache.james.mailets.configuration.ProcessorConfiguration; import org.apache.james.probe.DataProbe; import org.apache.james.transport.mailets.LocalDelivery; -import org.apache.james.transport.mailets.Null; import org.apache.james.transport.mailets.RemoveMimeHeader; import org.apache.james.transport.mailets.ToProcessor; +import org.apache.james.transport.mailets.ToRepository; import org.apache.james.transport.matchers.All; import org.apache.james.transport.matchers.RemoteAddrInNetwork; import org.apache.james.transport.matchers.RemoteAddrNotInNetwork; import org.apache.james.utils.DataProbeImpl; import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.MailRepositoryProbeImpl; import org.apache.james.utils.SMTPMessageSender; import org.junit.After; import org.junit.Before; @@ -57,6 +56,7 @@ public class NetworkMatcherIntegrationTest { private static final String JAMES_APACHE_ORG = "james.org"; private static final String FROM = "fromuser@" + JAMES_APACHE_ORG; + private static final String DROPPED_MAILS = "file://var/mail/dropped-mails/"; @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -109,10 +109,11 @@ public class NetworkMatcherIntegrationTest { .build(); } - private MailetConfiguration dropAllMailMailet() { + private MailetConfiguration toRepository() { return MailetConfiguration.builder() .matcher(All.class) - .mailet(Null.class) + .mailet(ToRepository.class) + .addProperty("repositoryPath", DROPPED_MAILS) .build(); } @@ -131,7 +132,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG, FROM, PASSWORD); @@ -155,7 +156,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG, FROM, PASSWORD); @@ -179,7 +180,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG, FROM, PASSWORD); @@ -203,7 +204,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG, FROM, PASSWORD); @@ -227,7 +228,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG, FROM, PASSWORD); @@ -251,7 +252,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG, FROM, PASSWORD); @@ -275,7 +276,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG); @@ -285,8 +286,8 @@ public class NetworkMatcherIntegrationTest { calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent); - Thread.sleep(TimeUnit.SECONDS.toMillis(10)); - + MailRepositoryProbeImpl repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1); assertThat(imapMessageReader.userReceivedMessage(FROM, PASSWORD)).isFalse(); } } @@ -301,7 +302,7 @@ public class NetworkMatcherIntegrationTest { .mailet(ToProcessor.class) .addProperty("processor", "transport") .build()) - .addMailet(dropAllMailMailet())); + .addMailet(toRepository())); try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, JAMES_APACHE_ORG); @@ -311,8 +312,8 @@ public class NetworkMatcherIntegrationTest { calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent); - Thread.sleep(TimeUnit.SECONDS.toMillis(10)); - + MailRepositoryProbeImpl repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1); assertThat(imapMessageReader.userReceivedMessage(FROM, PASSWORD)).isFalse(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/8eb8bf1a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java index 8b6160e..070eb09 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/SmtpAuthIntegrationTest.java @@ -21,8 +21,6 @@ package org.apache.james.mailets; import static org.assertj.core.api.Assertions.assertThat; -import java.util.concurrent.TimeUnit; - import org.apache.james.MemoryJamesServerMain; import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.MailetConfiguration; @@ -30,13 +28,14 @@ import org.apache.james.mailets.configuration.MailetContainer; import org.apache.james.mailets.configuration.ProcessorConfiguration; import org.apache.james.probe.DataProbe; import org.apache.james.transport.mailets.LocalDelivery; -import org.apache.james.transport.mailets.Null; import org.apache.james.transport.mailets.RemoveMimeHeader; import org.apache.james.transport.mailets.ToProcessor; +import org.apache.james.transport.mailets.ToRepository; import org.apache.james.transport.matchers.All; import org.apache.james.transport.matchers.SMTPAuthSuccessful; import org.apache.james.utils.DataProbeImpl; import org.apache.james.utils.IMAPMessageReader; +import org.apache.james.utils.MailRepositoryProbeImpl; import org.apache.james.utils.SMTPMessageSender; import org.junit.After; import org.junit.Before; @@ -56,6 +55,7 @@ public class SmtpAuthIntegrationTest { private static final String JAMES_APACHE_ORG = "james.org"; private static final String FROM = "fromuser@" + JAMES_APACHE_ORG; + private static final String DROPPED_MAILS = "file://var/mail/dropped-mails/"; @Rule @@ -128,7 +128,8 @@ public class SmtpAuthIntegrationTest { .enableJmx(true) .addMailet(MailetConfiguration.builder() .matcher(All.class) - .mailet(Null.class) + .mailet(ToRepository.class) + .addProperty("repositoryPath", DROPPED_MAILS) .build()) .build(); } @@ -162,8 +163,8 @@ public class SmtpAuthIntegrationTest { calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent); - Thread.sleep(TimeUnit.SECONDS.toMillis(10)); - + MailRepositoryProbeImpl repositoryProbe = jamesServer.getProbe(MailRepositoryProbeImpl.class); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> repositoryProbe.getRepositoryMailCount(DROPPED_MAILS) == 1); assertThat(imapMessageReader.userReceivedMessage(FROM, PASSWORD)).isFalse(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org