You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/07/25 02:59:03 UTC

[22/29] james-project git commit: JAMES-2469 RabbitMQ as a class rule

JAMES-2469 RabbitMQ as a class rule


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

Branch: refs/heads/master
Commit: 1169a7d3220d0a4db57db9745f2434bddaad021b
Parents: 4803007
Author: benwa <bt...@linagora.com>
Authored: Sat Jul 14 11:35:05 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 25 09:35:48 2018 +0700

----------------------------------------------------------------------
 .../transport/mailets/ICSAttachmentWorkflowTest.java     | 10 ++++++----
 .../apache/james/transport/mailets/amqp/AmqpRule.java    | 11 +++++++++--
 2 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1169a7d3/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
index 8c8a794..997251e 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/ICSAttachmentWorkflowTest.java
@@ -52,9 +52,9 @@ import org.apache.james.utils.SMTPMessageSender;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
 
 import com.google.common.collect.ImmutableList;
@@ -426,14 +426,15 @@ public class ICSAttachmentWorkflowTest {
             "END:VCALENDAR\r\n" +
             "";
 
-    public SwarmGenericContainer rabbitMqContainer = new SwarmGenericContainer(Images.RABBITMQ)
+    @ClassRule
+    public static SwarmGenericContainer rabbitMqContainer = new SwarmGenericContainer(Images.RABBITMQ)
             .withAffinityToContainer();
+    @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
     public AmqpRule amqpRule = new AmqpRule(rabbitMqContainer, EXCHANGE_NAME, ROUTING_KEY);
 
     @Rule
-    public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(rabbitMqContainer).around(amqpRule);
-    @Rule
     public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
     @Rule
     public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN);
@@ -550,6 +551,7 @@ public class ICSAttachmentWorkflowTest {
     @After
     public void tearDown() throws Exception {
         jamesServer.shutdown();
+        amqpRule.readAll();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1169a7d3/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/amqp/AmqpRule.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/amqp/AmqpRule.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/amqp/AmqpRule.java
index c117b8d..8198236 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/amqp/AmqpRule.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/amqp/AmqpRule.java
@@ -37,6 +37,8 @@ import com.rabbitmq.client.GetResponse;
 
 public class AmqpRule extends ExternalResource {
 
+    private static final boolean AUTO_ACK = true;
+
     private final SwarmGenericContainer rabbitMqContainer;
     private final String exchangeName;
     private final String routingKey;
@@ -68,14 +70,19 @@ public class AmqpRule extends ExternalResource {
         return amqpUri;
     }
 
+    public void readAll() throws IOException {
+        while (channel.basicGet(queueName, AUTO_ACK) != null) {
+
+        }
+    }
+
     public Optional<String> readContent() throws IOException {
         return readContentAsBytes()
             .map(value -> new String(value, StandardCharsets.UTF_8));
     }
 
     public Optional<byte[]> readContentAsBytes() throws IOException {
-        boolean autoAck = true;
-        return Optional.ofNullable(channel.basicGet(queueName, autoAck))
+        return Optional.ofNullable(channel.basicGet(queueName, AUTO_ACK))
             .map(GetResponse::getBody);
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org