Unit tests for Marathon binding
authorDavid Bosschaert <davidb@apache.org>
Thu, 15 Jun 2017 10:41:39 +0000 (11:41 +0100)
committerDavid Bosschaert <davidb@apache.org>
Thu, 15 Jun 2017 10:41:39 +0000 (11:41 +0100)
containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ServiceImpl.java
containers-marathon/src/test/java/org/apache/aries/containers/marathon/impl/ServiceImplTest.java

index 182d4b4..7cf926f 100644 (file)
@@ -72,7 +72,7 @@ class ServiceImpl implements Service {
     @Override
     public void setInstanceCount(int count) {
         App updatedApp = new App();
-        updatedApp.setInstances(count);;
+        updatedApp.setInstances(count);
         marathonClient.updateApp(marathonAppID, updatedApp, true);
     }
 
index b435d72..d02ddea 100644 (file)
@@ -30,6 +30,8 @@ import org.apache.aries.containers.Container;
 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;
 import static org.junit.Assert.assertSame;
@@ -37,6 +39,7 @@ import static org.junit.Assert.assertSame;
 import mesosphere.marathon.client.Marathon;
 import mesosphere.marathon.client.model.v2.App;
 import mesosphere.marathon.client.model.v2.GetAppResponse;
+import mesosphere.marathon.client.model.v2.Result;
 import mesosphere.marathon.client.model.v2.Task;
 
 public class ServiceImplTest {
@@ -129,6 +132,34 @@ public class ServiceImplTest {
         assertEquals(new HashSet<>(Arrays.asList("task1", "task2")), foundTasks);
     }
 
+    @Test
+    public void testSetInstanceCount() throws Exception {
+        List<App> updatedApps = new ArrayList<>();
+
+        Marathon mc = Mockito.mock(Marathon.class);
+        Mockito.when(mc.updateApp(Mockito.eq("mid1"), Mockito.isA(App.class), Mockito.eq(true))).
+            then(new Answer<Result>() {
+                @Override
+                public Result answer(InvocationOnMock invocation) throws Throwable {
+                    updatedApps.add((App) invocation.getArguments()[1]);
+                    return Mockito.mock(Result.class);
+                }
+            });
+
+        ServiceConfig cfg = ServiceConfig.builder("svc1", "a/b/c:d").build();
+
+        App app = new App();
+        app.setId("mid1");
+        ServiceImpl svc = new ServiceImpl(mc, app, cfg);
+
+        assertEquals("Precondition", 0, updatedApps.size());
+        svc.setInstanceCount(5);
+        assertEquals(1, updatedApps.size());
+
+        App updated = updatedApps.iterator().next();
+        assertEquals(5, (int) updated.getInstances());
+    }
+
     private GetAppResponse getAppResponse(App a) {
         GetAppResponse gar = Mockito.mock(GetAppResponse.class);
         Mockito.when(gar.getApp()).thenReturn(a);