You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/07/28 16:21:53 UTC

[2/4] git commit: Improve DynamicFabric test coverage

Improve DynamicFabric test coverage

- for when fabric has existing children


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/fede9621
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/fede9621
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/fede9621

Branch: refs/heads/master
Commit: fede9621588ddf2a60cb58015db4cc00ab60deaa
Parents: e315de3
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jul 21 14:21:30 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jul 21 14:31:37 2014 +0100

----------------------------------------------------------------------
 .../entity/group/DynamicFabricTest.java         | 75 ++++++++++++++++++++
 1 file changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fede9621/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
index 85f032c..ea024b6 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
@@ -53,6 +53,7 @@ import brooklyn.test.Asserts;
 import brooklyn.test.TestUtils;
 import brooklyn.test.entity.BlockingEntity;
 import brooklyn.test.entity.TestEntity;
+import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.repeat.Repeater;
 
@@ -404,6 +405,80 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
         assertEquals(((TestEntity)getMember(child, 1)).getConfigureProperties().get("fromFabric"), null);
 	}
 
+    @Test
+    public void testExistingChildrenStarted() throws Exception {
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+            .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
+        
+        List<TestEntity> existingChildren = Lists.newArrayList();
+        for (int i = 0; i < 3; i++) {
+            existingChildren.add(fabric.addChild(EntitySpec.create(TestEntity.class)));
+        }
+        app.start(locs);
+
+        // Expect only these existing children
+        Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren);
+
+        // Expect one location per existing child
+        List<Location> remainingLocs = MutableList.copyOf(locs);
+        for (Entity existingChild : existingChildren) {
+            Collection<Location> childLocs = existingChild.getLocations();
+            assertEquals(childLocs.size(), 1, "childLocs="+childLocs);
+            assertTrue(remainingLocs.removeAll(childLocs));
+        }
+    }
+
+    @Test
+    public void testExistingChildrenStartedRoundRobiningAcrossLocations() throws Exception {
+        List<Location> locs = ImmutableList.of(loc1, loc2);
+        
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+            .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
+        
+        List<TestEntity> existingChildren = Lists.newArrayList();
+        for (int i = 0; i < 4; i++) {
+            existingChildren.add(fabric.addChild(EntitySpec.create(TestEntity.class)));
+        }
+        app.start(locs);
+
+        // Expect only these existing children
+        Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren);
+
+        // Expect one location per existing child (round-robin)
+        // Expect one location per existing child
+        List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).addAll(locs).build();
+        for (Entity existingChild : existingChildren) {
+            Collection<Location> childLocs = existingChild.getLocations();
+            assertEquals(childLocs.size(), 1, "childLocs="+childLocs);
+            assertTrue(remainingLocs.remove(Iterables.get(childLocs, 0)), "childLocs="+childLocs+"; remainingLocs="+remainingLocs+"; allLocs="+locs);
+        }
+    }
+
+    @Test
+    public void testExistingChildrenToppedUpWhenNewMembersIfMoreLocations() throws Exception {
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+            .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
+        
+        TestEntity existingChild = fabric.addChild(EntitySpec.create(TestEntity.class));
+        
+        app.start(locs);
+
+        // Expect three children: the existing one, and one per other location
+        assertEquals(fabric.getChildren().size(), 3, "children="+fabric.getChildren());
+        assertTrue(fabric.getChildren().contains(existingChild), "children="+fabric.getChildren()+"; existingChild="+existingChild);
+
+        List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).build();
+        for (Entity child : fabric.getChildren()) {
+            Collection<Location> childLocs = child.getLocations();
+            assertEquals(childLocs.size(), 1, "childLocs="+childLocs);
+            assertTrue(remainingLocs.remove(Iterables.get(childLocs, 0)), "childLocs="+childLocs+"; remainingLocs="+remainingLocs+"; allLocs="+locs);
+        }
+    }
+
 	private Entity getGrandchild(Entity entity, int childIndex, int grandchildIndex) {
         Entity child = getChild(entity, childIndex);
         return Iterables.get(child.getChildren(), grandchildIndex);