aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject aries-containers git commit: Unit test for docker local health checks.
Date Fri, 16 Jun 2017 12:10:46 GMT
Repository: aries-containers
Updated Branches:
  refs/heads/master 8c2c7e511 -> 623c15a25


Unit test for docker local health checks.


Project: http://git-wip-us.apache.org/repos/asf/aries-containers/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-containers/commit/623c15a2
Tree: http://git-wip-us.apache.org/repos/asf/aries-containers/tree/623c15a2
Diff: http://git-wip-us.apache.org/repos/asf/aries-containers/diff/623c15a2

Branch: refs/heads/master
Commit: 623c15a250b9837a4afa1c6e9c04ec52314f17a1
Parents: 8c2c7e5
Author: David Bosschaert <davidb@apache.org>
Authored: Fri Jun 16 13:10:27 2017 +0100
Committer: David Bosschaert <davidb@apache.org>
Committed: Fri Jun 16 13:10:27 2017 +0100

----------------------------------------------------------------------
 .../local/impl/LocalDockerServiceManager.java   |  3 ++
 .../impl/LocalDockerServiceManagerTest.java     | 41 ++++++++++++++++++++
 2 files changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-containers/blob/623c15a2/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
----------------------------------------------------------------------
diff --git a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
index 6e0f4a2..f5c0575 100644
--- a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
+++ b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
@@ -164,6 +164,9 @@ public class LocalDockerServiceManager implements ServiceManager {
             command.add(hc.getInterval() + "s");
             command.add("--health-retries");
             command.add("" + hc.getMaxFailures());
+// TODO Add this when docker supports it in a release.
+//            command.add("--health-start-period");
+//            command.add(hc.getGracePeriod() + "s");
             command.add("--health-timeout");
             command.add(hc.getTimeout() + "s");
         }

http://git-wip-us.apache.org/repos/asf/aries-containers/blob/623c15a2/containers-docker-local/src/test/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManagerTest.java
----------------------------------------------------------------------
diff --git a/containers-docker-local/src/test/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManagerTest.java
b/containers-docker-local/src/test/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManagerTest.java
index 934bd52..71c2ad2 100644
--- a/containers-docker-local/src/test/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManagerTest.java
+++ b/containers-docker-local/src/test/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManagerTest.java
@@ -28,10 +28,13 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.aries.containers.Container;
+import org.apache.aries.containers.HealthCheck;
 import org.apache.aries.containers.Service;
 import org.apache.aries.containers.ServiceConfig;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 
 import static org.junit.Assert.assertEquals;
 
@@ -125,4 +128,42 @@ public class LocalDockerServiceManagerTest {
 
         assertEquals(new HashSet<>(Arrays.asList("svc1", "svc2", "svc3")), sm.listServices());
     }
+
+    @Test
+    public void testCreateDockerContainerWithHealthCheck() throws Exception {
+        Map<String, String> expectedArgs = new HashMap<>();
+        expectedArgs.put("--health-cmd", "curl --fail http://localhost:8080 || exit 1");
+        expectedArgs.put("--health-interval", "71s");
+        expectedArgs.put("--health-retries", "11");
+        expectedArgs.put("--health-timeout", "90s");
+        LocalDockerController dc = Mockito.mock(LocalDockerController.class);
+        Mockito.when(dc.run(Mockito.anyListOf(String.class))).then(new Answer<DockerContainerInfo>()
{
+            @Override
+            public DockerContainerInfo answer(InvocationOnMock invocation) throws Throwable
{
+                @SuppressWarnings("unchecked")
+                List<String> sl = (List<String>) invocation.getArguments()[0];
+
+                Map<String,String> ea = new HashMap<>(expectedArgs);
+                for (int i=0; i < sl.size() - 1; i++) {
+                    ea.remove(sl.get(i), sl.get(i+1));
+                }
+                if (ea.size() > 0) {
+                    // not all expected args found
+                    return null;
+                }
+                return new DockerContainerInfo("anid", "99.99.99.99");
+            }
+        });
+
+        LocalDockerServiceManager sm = new LocalDockerServiceManager(dc);
+
+        HealthCheck hc = HealthCheck.builder(HealthCheck.Type.COMMAND).
+                parameters("curl --fail http://localhost:8080 || exit 1").
+                interval(71).maxFailures(11).timeout(90).build();
+        ServiceConfig sc = ServiceConfig.builder("MySvc", "img1").healthCheck(hc).build();
+        ContainerImpl ctr = sm.createDockerContainer(sc);
+
+        assertEquals("anid", ctr.getID());
+        assertEquals("99.99.99.99", ctr.getHostName());
+    }
 }


Mime
View raw message