james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1709399 - in /james/project/trunk/mpt/impl/imap-mailbox/cyrus: pom.xml src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java
Date Mon, 19 Oct 2015 12:07:14 GMT
Author: matthieu
Date: Mon Oct 19 12:07:14 2015
New Revision: 1709399

URL: http://svn.apache.org/viewvc?rev=1709399&view=rev
Log:
MPT-31 make sure service is ok at container creation time

Modified:
    james/project/trunk/mpt/impl/imap-mailbox/cyrus/pom.xml
    james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java
    james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java

Modified: james/project/trunk/mpt/impl/imap-mailbox/cyrus/pom.xml
URL: http://svn.apache.org/viewvc/james/project/trunk/mpt/impl/imap-mailbox/cyrus/pom.xml?rev=1709399&r1=1709398&r2=1709399&view=diff
==============================================================================
--- james/project/trunk/mpt/impl/imap-mailbox/cyrus/pom.xml (original)
+++ james/project/trunk/mpt/impl/imap-mailbox/cyrus/pom.xml Mon Oct 19 12:07:14 2015
@@ -130,6 +130,11 @@
             </activation>
             <dependencies>
                 <dependency>
+                    <groupId>com.jayway.awaitility</groupId>
+                    <artifactId>awaitility</artifactId>
+                    <version>1.6.5</version>
+                </dependency>
+                <dependency>
                     <groupId>com.spotify</groupId>
                     <artifactId>docker-client</artifactId>
                     <version>2.7.25</version>

Modified: james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java?rev=1709399&r1=1709398&r2=1709399&view=diff
==============================================================================
--- james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java
(original)
+++ james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java
Mon Oct 19 12:07:14 2015
@@ -122,6 +122,7 @@ public class CyrusHostSystem extends Ext
         try {
             Session session = newSession(null);
             try {
+                session.start();
                 protocolSession.runSessions(new Session[]{session});
             } finally {
                 session.stop();

Modified: james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java?rev=1709399&r1=1709398&r2=1709399&view=diff
==============================================================================
--- james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java
(original)
+++ james/project/trunk/mpt/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java
Mon Oct 19 12:07:14 2015
@@ -18,9 +18,15 @@
  ****************************************************************/
 package org.apache.james.mpt.imapmailbox.cyrus.host;
 
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.concurrent.TimeUnit;
+
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
+import com.jayway.awaitility.Awaitility;
 import com.spotify.docker.client.DefaultDockerClient;
 import com.spotify.docker.client.DockerException;
 import com.spotify.docker.client.messages.ContainerConfig;
@@ -57,9 +63,27 @@ public class Docker {
     public ContainerCreation start() throws Exception {
         ContainerCreation container = dockerClient.createContainer(containerConfig);
         dockerClient.startContainer(container.id(), ALL_PORTS_HOST_CONFIG);
+        waitingForSocketToBeReady(container);
         return container;
     }
 
+    private void waitingForSocketToBeReady(final ContainerCreation container) {
+        Awaitility
+            .await()
+            .atMost(30, TimeUnit.SECONDS)
+            .with()
+            .pollInterval(10, TimeUnit.MILLISECONDS)
+            .and()
+            .ignoreExceptions()
+            .until(() -> socketIsReady(container));
+    }
+
+    private boolean socketIsReady(ContainerCreation container) throws UnknownHostException,
IOException {
+        try (Socket socket = new Socket(getHost(container), getIMAPPort(container))) {
+            return socket.getInputStream().read() >= 0;
+        }
+    }
+
     public void stop(ContainerCreation container) {
         try {
             dockerClient.killContainer(container.id());



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


Mime
View raw message