Repository: james-project
Updated Branches:
  refs/heads/master 1456d3729 -> ac89a62f8


PROTOCOLS-115 Use ConcurrentTestRunner to handle threads


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

Branch: refs/heads/master
Commit: c23ac898b92c092c83224236b7a4c2d865ab8150
Parents: 4eb5e7d
Author: Raphael Ouazana <[email protected]>
Authored: Thu Feb 2 10:28:40 2017 +0100
Committer: Raphael Ouazana <[email protected]>
Committed: Thu Feb 2 15:23:43 2017 +0100

----------------------------------------------------------------------
 protocols/pom.xml                               |  7 ++-
 protocols/smtp/pom.xml                          |  4 ++
 .../protocols/smtp/AbstractSMTPServerTest.java  | 55 ++++++--------------
 3 files changed, 26 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c23ac898/protocols/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/pom.xml b/protocols/pom.xml
index 3eb0ca3..1e44a27 100644
--- a/protocols/pom.xml
+++ b/protocols/pom.xml
@@ -65,7 +65,12 @@
     </properties>
 
     <dependencyManagement>
-        <dependencies>
+            <dependencies>
+            <dependency>
+                <groupId>org.apache.james</groupId>
+                <artifactId>james-server-util</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.apache.james.protocols</groupId>
                 <artifactId>protocols-pop3</artifactId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/c23ac898/protocols/smtp/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/smtp/pom.xml b/protocols/smtp/pom.xml
index b96cc1d..7f4c049 100644
--- a/protocols/smtp/pom.xml
+++ b/protocols/smtp/pom.xml
@@ -35,6 +35,10 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>james-server-util</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.james.protocols</groupId>
             <artifactId>protocols-api</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/c23ac898/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
----------------------------------------------------------------------
diff --git 
a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
 
b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
index d5027e8..27b3804 100644
--- 
a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
+++ 
b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.protocols.smtp;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -30,6 +31,7 @@ import java.net.SocketException;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.configuration.Configuration;
@@ -52,6 +54,7 @@ import org.apache.james.protocols.smtp.hook.MailHook;
 import org.apache.james.protocols.smtp.hook.MessageHook;
 import org.apache.james.protocols.smtp.hook.RcptHook;
 import org.apache.james.protocols.smtp.utils.TestMessageHook;
+import org.apache.james.util.concurrency.ConcurrentTestRunner;
 import org.junit.Test;
 
 import com.google.common.base.Charsets;
@@ -99,21 +102,20 @@ public abstract class AbstractSMTPServerTest {
         try {
             server = createServer(createProtocol(hook));
             server.bind();
-            InetSocketAddress bindedAddress = new 
ProtocolServerUtils(server).retrieveBindedAddress();
 
-            String mailContent = CharStreams.toString(new 
InputStreamReader(ClassLoader.getSystemResourceAsStream("a50.eml"), 
Charsets.US_ASCII));
-            Thread thread1 = new SendThread(server, bindedAddress, 
mailContent);
-            Thread thread2 = new SendThread(server, bindedAddress, 
mailContent);
-            Thread thread3 = new SendThread(server, bindedAddress, 
mailContent);
-            Thread thread4 = new SendThread(server, bindedAddress, 
mailContent);
-            thread1.start();
-            thread2.start();
-            thread3.start();
-            thread4.start();
-            thread1.join(1000);
-            thread2.join(1000);
-            thread3.join(1000);
-            thread4.join(1000);
+            final ProtocolServer finalServer = server;
+            final InetSocketAddress bindedAddress = new 
ProtocolServerUtils(server).retrieveBindedAddress();
+            final String mailContent = CharStreams.toString(new 
InputStreamReader(ClassLoader.getSystemResourceAsStream("a50.eml"), 
Charsets.US_ASCII));
+            int threadCount = 4;
+            int updateCount = 1;
+            assertThat(new ConcurrentTestRunner(threadCount, updateCount, new 
ConcurrentTestRunner.BiConsumer() {
+                @Override
+                public void consume(int threadNumber, int step) throws 
Exception {
+                    send(finalServer, bindedAddress, mailContent);
+                }
+            }).run()
+                .awaitTermination(1, TimeUnit.MINUTES))
+                .isTrue();
 
             Iterator<MailEnvelope> queued = hook.getQueued().iterator();
             assertTrue(queued.hasNext());
@@ -137,31 +139,6 @@ public abstract class AbstractSMTPServerTest {
             }
         }
     }
-    
-    public class SendThread extends Thread {
-        private ProtocolServer server;
-        private InetSocketAddress bindedAddress;
-        private String msg;
-
-        public SendThread(ProtocolServer server, InetSocketAddress 
bindedAddress, String msg) {
-            this.server = server;
-            this.bindedAddress = bindedAddress;
-            this.msg = msg;
-        }
-        
-        @Override
-        public void run() {
-            try {
-                send(server, bindedAddress, msg);
-            } catch (SocketException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            } catch (IOException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-        }
-    }
 
     private void send(ProtocolServer server, InetSocketAddress bindedAddress, 
String msg) throws SocketException, IOException {
         SMTPClient client = createClient();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to